Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: implement buffer and scanBuffer planNodes #37050

Closed
jordanlewis opened this issue Apr 23, 2019 · 0 comments · Fixed by #37137
Closed

sql: implement buffer and scanBuffer planNodes #37050

jordanlewis opened this issue Apr 23, 2019 · 0 comments · Fixed by #37137
Assignees
Labels
A-sql-fks C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)

Comments

@jordanlewis
Copy link
Member

jordanlewis commented Apr 23, 2019

A buffer planNode should consume input rows, write them to a buffer, and pass the rows through to the next node in the chain.

A scanBuffer planNode references a single buffer planNode and behaves like an iterator into that buffer. It doesn't live on the "main path" of a planNode tree - something else has to Next it to start it consuming from the buffer.

Together, these two nodes enable a couple of use cases:

  1. multiple references to a single WITH clause in a CTE, which is a known limitation: sql: multi-use common table expressions #21084
  2. optimizer-driven foreign key checks

For use case 2, you can imagine trees like the following making up a foreign key check, together (see issue #37053 for errorIfRows):

[valuesNode] -> [buffer 'x'] -> insertNode`
[scanBuffer 'x'] -> [lookup antijoin into reference table] -> [errorIfRows]
@jordanlewis jordanlewis added the C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) label Apr 23, 2019
craig bot pushed a commit that referenced this issue May 15, 2019
37137: sql: add buffer and scanBuffer nodes r=yuzefovich a=yuzefovich

Adds bufferNode that consumes its input, stores all the rows in a
buffer, and then proceeds on passing the rows through. The buffer
can be iterated over multiple times using scanBuffer node that is
referencing a single bufferNode.

Fixes: #37050.

Release note: None

Co-authored-by: Yahor Yuzefovich <yahor@cockroachlabs.com>
@craig craig bot closed this as completed in #37137 May 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-fks C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants