cockroach icon indicating copy to clipboard operation
cockroach copied to clipboard

sql: allowing window functions to maintain ordering

Open roncrdb opened this issue 7 years ago • 9 comments

User is trying to replicate HBase data model on CRDB.

At the moment, that current implementation of window functions doesn't guarantee preservation of the ordering.

Having windower maintain order could be a possible solution.

@yuzefovich how could we prioritize this?

Jira issue: CRDB-4506

roncrdb avatar Mar 28 '19 21:03 roncrdb

Zendesk ticket #3227 has been linked to this issue.

tim-o avatar Mar 28 '19 21:03 tim-o

@yuzefovich I'm happy to help move this forward. I can participate with the required changes or help validate the changes.

plaflamme avatar Mar 29 '19 14:03 plaflamme

This is part of #34251.

justinj avatar Mar 29 '19 15:03 justinj

@plaflamme Thanks for your willingness to contribute! We are happy to guide you through the process of working on this feature.

However, please keep in mind that making windower maintain the ordering is not sufficient - the planning code also needs to be taught about this, and at the moment cost-based optimizer doesn't support window functions at all, so even if the "execution" part is done soon, we'll need to wait for the "planning" part (which is I think on a medium to long-term horizon).

yuzefovich avatar Apr 01 '19 20:04 yuzefovich

@yuzefovich Thanks for the head's up (sorry for the delay GH notifications are failing me at the moment).

I'm obviously not familiar with CDB's distributed SQL engine, but I was hoping that window functions would only need to expose whether or not they're producing stable ordering to the planner. If they are, then the planner could leverage that, and if not it'd have no ability to optimize those steps (the current state of things). This could then be incrementally added to window functions (some would probably be harder than others). I guess I'm assuming that the planner can already optimize out sorting if ordering is guaranteed by certain steps.

FMI: what would be the purpose of maintaining stable ordering at execution time, but not be able to leverage this during planning?

FMI2: is there some documentation or a RFC / specification I can look at for the current implementation plan?

plaflamme avatar Apr 30 '19 00:04 plaflamme

@plaflamme yeah, a single GH notification can easily get lost, so no worries there.

  1. There would not be any benefit in maintaining stable ordering during execution if the planner cannot use it - both planning and execution have to know about it / implement it for it to work.
  2. Unfortunately, there is no documentation. Probably, the closest to that is a draft doc (https://docs.google.com/document/d/1hWfmhIXfIQxAovxZd4NM-6BcwhxQfUDsYevKTiKXDWk/edit?usp=sharing) that I wrote up when distributed window functions PR was being reviewed last Summer. It is, however, very outdated, so I'm not sure whether it's worth reading.

On the bright side, right now there is a lot of progress going on with window functions: the optimizer already supports them (without any optimizations yet though), and I'm working on adding the support to vectorized engine as well.

yuzefovich avatar Apr 30 '19 03:04 yuzefovich

@yuzefovich Ok great, sounds like it's moving forward; exciting! Is there an "umbrella" GH issue this work is happening under? I'll go ahead and follow that one.

plaflamme avatar Apr 30 '19 20:04 plaflamme

@plaflamme there is no issue that tracks progress in regards to maintaining the stable ordering (apart from this one), but you probably are interested in #34251 and in #37040.

yuzefovich avatar Apr 30 '19 20:04 yuzefovich

We have marked this issue as stale because it has been inactive for 18 months. If this issue is still relevant, removing the stale label or adding a comment will keep it active. Otherwise, we'll close it in 10 days to keep the issue queue tidy. Thank you for your contribution to CockroachDB!

github-actions[bot] avatar Nov 23 '23 11:11 github-actions[bot]