-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: v21.1.2: non-intersecting sets assertion from ordering_choice #79644
Comments
Hi, this was me reproducing a crash that I experienced in a non-telemetry enabled cluster. The following SQL triggers the crash: CREATE TABLE items (
id INT8 PRIMARY KEY,
project_id INT8 NOT NULL,
name STRING(1024),
/* The name field and this constraint are required for reproduction, though not used in the query. */
UNIQUE (project_id, name)
);
CREATE TABLE item_revisions (
item_id INT8 NOT NULL REFERENCES items,
revision_number INT4 NOT NULL,
PRIMARY KEY (item_id, revision_number)
);
CREATE TABLE item_revision_datasets (
item_id INT8 NOT NULL,
revision_number INT4 NOT NULL,
dataset_id INT8 NOT NULL,
PRIMARY KEY (item_id, revision_number, dataset_id),
/* This constraint is not required for reproduction. */
CONSTRAINT fk_item_revision FOREIGN KEY (item_id, revision_number) REFERENCES item_revisions (item_id, revision_number)
);
INSERT INTO items (id, project_id, name) VALUES (1, -9213355328025498762, '1');
INSERT INTO item_revisions (item_id, revision_number) VALUES (1, 0);
INSERT INTO item_revisions (item_id, revision_number) VALUES (1, 1);
INSERT INTO item_revision_datasets (item_id, revision_number, dataset_id) VALUES (1, 0, 10);
INSERT INTO item_revision_datasets (item_id, revision_number, dataset_id) VALUES (1, 0, 11);
INSERT INTO item_revision_datasets (item_id, revision_number, dataset_id) VALUES (1, 1, 12);
INSERT INTO item_revision_datasets (item_id, revision_number, dataset_id) VALUES (1, 1, 13);
SELECT
DISTINCT ON (item_revisions.item_id)
items.project_id, item_revisions.item_id, array_agg(item_revision_datasets.dataset_id) FROM item_revisions
INNER JOIN items ON items.id = item_revisions.item_id
INNER JOIN item_revision_datasets ON item_revisions.revision_number = item_revision_datasets.revision_number
GROUP BY (item_revisions.item_id, items.project_id, item_revisions.revision_number)
ORDER BY (item_revisions.item_id, item_revisions.revision_number)
; Happy to provide any further details that would assist you. I was running the official latest docker image in single node development mode. |
@tommilligan Thanks for providing detailed reproduction steps! We'll look into this. I've been able to reproduce back on v21.1.0, so I'm not labelling this a release blocker. |
Ah yes, sorry I should have given the original environment details as well. For the record, they are: $ cockroach version
Build Tag: v21.1.2
Build Time: 2021/06/07 18:09:50
Distribution: CCL
Platform: linux amd64 (x86_64-unknown-linux-gnu)
Go Version: go1.15.11
C Compiler: gcc 6.5.0
Build Commit ID: d9845bd3021b4f5b816bd8bcde58b90a73f0377c
Build Type: release |
Fixes cockroachdb#79644 Previously, a query with an ORDER BY clause a DISTINCT ON clause and a GROUP BY clause involving columns in different join tables may error out if there is an index on one of the GROUP BY's Optional OrderingChoice columns and that column is not in the ordering required by the ORDER BY clause. `FromOrderingWithOptCols` is called during construction of the group by expression, and builds a `GroupingPrivate` with `Ordering` of `Any` (no columns), but still includes the `Optional` grouping columns. This violates the rule stated in the comments for `Optional`: ``` ...if Columns is empty, then Optional must be as well. ``` Because of this unnormalized `OrderingChoice`, this makes it appear that the projected grouping column can provide the required ordering even though this column does not actually intersect with the ordering columns. A later call to `OrderingChoice.Intersection` is made in `groupByBuildChildReqOrdering` to find the intersection between required and provided orderings, which panics when it cannot build the intersection. `Optional` columns may only be added to an ordering when there is at least one ordering column, and this assumption is also made in the code that builds `OrderingChoice`s. To address this, this patch fixes all locations where an empty `OrderingChoice` which matches `Any` ordering is built by normalizing it so that the `Optional` column set is empty. Release note (bug fix): This patch fixes queries which involve an ORDER BY clause, a DISTINCT ON clause and a GROUP BY clause, which may sometimes error out depending on the columns referenced in those clauses.
This issue was autofiled by Sentry. It represents a crash or reported error on a live cluster with telemetry enabled.
Sentry link: https://sentry.io/organizations/cockroach-labs/issues/3172549581/?referrer=webhooks_plugin
Panic message:
Stacktrace (expand for inline code snippets):
cockroach/pkg/sql/opt/props/ordering_choice.go
Lines 421 to 423 in cad0000
cockroach/pkg/sql/opt/ordering/group_by.go
Lines 48 to 50 in cad0000
cockroach/pkg/sql/opt/ordering/ordering.go
Lines 39 to 41 in cad0000
cockroach/pkg/sql/opt/xform/physical_props.go
Lines 79 to 81 in cad0000
cockroach/pkg/sql/opt/xform/optimizer.go
Lines 506 to 508 in cad0000
cockroach/pkg/sql/opt/xform/optimizer.go
Lines 454 to 456 in cad0000
cockroach/pkg/sql/opt/xform/optimizer.go
Lines 254 to 256 in cad0000
cockroach/pkg/sql/opt/xform/optimizer.go
Lines 509 to 511 in cad0000
cockroach/pkg/sql/opt/xform/optimizer.go
Lines 454 to 456 in cad0000
cockroach/pkg/sql/opt/xform/optimizer.go
Lines 619 to 621 in cad0000
cockroach/pkg/sql/opt/xform/optimizer.go
Lines 585 to 587 in cad0000
cockroach/pkg/sql/opt/xform/optimizer.go
Lines 494 to 496 in cad0000
cockroach/pkg/sql/opt/xform/optimizer.go
Lines 454 to 456 in cad0000
cockroach/pkg/sql/opt/xform/optimizer.go
Lines 224 to 226 in cad0000
cockroach/pkg/sql/plan_opt.go
Lines 416 to 418 in cad0000
cockroach/pkg/sql/plan_opt.go
Lines 492 to 494 in cad0000
cockroach/pkg/sql/plan_opt.go
Lines 193 to 195 in cad0000
cockroach/pkg/sql/conn_executor_exec.go
Lines 1259 to 1261 in cad0000
cockroach/pkg/sql/conn_executor_exec.go
Lines 971 to 973 in cad0000
cockroach/pkg/sql/conn_executor_exec.go
Lines 708 to 710 in cad0000
cockroach/pkg/sql/conn_executor_exec.go
Lines 128 to 130 in cad0000
cockroach/pkg/sql/conn_executor.go
Lines 1704 to 1706 in cad0000
cockroach/pkg/sql/conn_executor.go
Lines 1706 to 1708 in cad0000
cockroach/pkg/sql/conn_executor.go
Lines 1628 to 1630 in cad0000
cockroach/pkg/sql/conn_executor.go
Lines 667 to 669 in cad0000
cockroach/pkg/sql/pgwire/conn.go
Lines 647 to 649 in cad0000
/usr/local/go/src/runtime/asm_amd64.s#L1370-L1372 in runtime.goexit
v21.2.8
Jira issue: CRDB-14962
The text was updated successfully, but these errors were encountered: