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

release-2.1: assorted CTE fixes #31051

Merged

Conversation

knz
Copy link
Contributor

@knz knz commented Oct 7, 2018

Backport:

Please see individual PRs for details.

/cc @cockroachdb/release

Justin Jaffray and others added 6 commits October 7, 2018 10:43
This commit introduces Cockroach-style single-use CTEs to the optimizer.
Such CTEs cannot be referenced more than once in a query.

Release note: None
These two checks are now exhaustive, meaning anything missing from them
going forward is an error.

Release note: None
The SQL standard (and pg) specifies that CTEs containing mutations are
executed no matter how / how many times they are used in the remainder
of the query.

Meanwhile the heuristic planner + execution machinery is currently
unable to force the execution of CTEs containing mutations if they are
not otherwise used in the rest of the query.

However meanwhile they are also accepted silently -- i.e. CockroachDB
silently fails to do what the semantics require.

This patch changes the behavior to instead report an error "feature
not supported".

Release note (bug fix): CockroachDB now reports an unimplemented error
when a common table expression containing INSERT/UPDATE/UPSERT/DELETE
is not otherwise used in the remainder of the query.
Prior to this patch, CockroachDB silently ignored WITH clauses within
parentheses, so that the following SQL would return incorrect results:

```
CREATE TABLE t(x INT);
(WITH t AS (SELECT 1) TABLE t);
```

(note: `WITH ...` *without* parentheses did work fine)

This patch fixes this particular issue, and causes CockroachDB to
issue an "unimplemented error" in other cases not supported yet, for
example when there are multiple nested WITH clauses within
parentheses.

Release note (bug fix): CockroachDB does not silently ignore WITH
clauses within parentheses any more.
Release note (sql change): CockroachDB now supports CTEs inside views.
@knz knz requested review from jordanlewis, justinj and a team October 7, 2018 08:43
@knz knz requested a review from a team as a code owner October 7, 2018 08:43
@knz knz requested review from a team October 7, 2018 08:43
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@rytaft
Copy link
Collaborator

rytaft commented Oct 7, 2018

First 5 commits LGTM. I'll let someone review the last one who reviewed the original PR.

@knz knz merged commit 0baee4f into cockroachdb:release-2.1 Oct 11, 2018
@knz knz deleted the backport2.1-30858-30939-31003-31004-31007 branch October 11, 2018 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants