Skip to content

Commit

Permalink
Merge pull request #88480 from DrewKimball/backport22.1-87888
Browse files Browse the repository at this point in the history
release-22.1: opt: include optional columns when remapping Project provided ordering
  • Loading branch information
DrewKimball authored Sep 23, 2022
2 parents bdcab67 + 2ba377c commit f970524
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/sql/opt/ordering/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func projectBuildProvided(expr memo.RelExpr, required *props.OrderingChoice) opt
// can cause the child to provide an ordering that is equivalent to the
// required ordering, but which the parent Project cannot prove is equivalent
// because its FDs have less information. This can lead to a panic later on.
ordCols := required.ColSet()
ordCols := required.ColSet().Union(required.Optional)
if !ordCols.SubsetOf(expr.Relational().OutputCols) {
panic(errors.AssertionFailedf("expected required columns to be a subset of output columns"))
}
Expand Down
43 changes: 43 additions & 0 deletions pkg/sql/opt/xform/testdata/physprops/ordering
Original file line number Diff line number Diff line change
Expand Up @@ -2609,3 +2609,46 @@ sort
│ └── fd: (6)-->(5)
└── filters
└── (t0_85393.rowid:2 IS NULL) OR (t1_85393.rowid:6 = t0_85393.rowid:2) [outer=(2,6)]

# Regression test for #87806 - include optional columns when remapping Project
# provided ordering.
exec-ddl
CREATE TABLE table87806 (
col1_0 TIMESTAMPTZ, col1_1 BOOL, col1_2 REGPROC, col1_3 REGNAMESPACE,
PRIMARY KEY (col1_1, col1_2 ASC),
UNIQUE (col1_1 ASC),
INDEX (col1_3)
);
----

opt format=hide-all
SELECT tab_171969.col1_3
FROM table87806 AS tab_171967
JOIN table87806 AS tab_171968
JOIN table87806@table87806_col1_3_idx AS tab_171969
ON tab_171968.col1_1 = tab_171969.col1_1
AND tab_171968.col1_3 = tab_171969.col1_3
AND tab_171968.col1_3 = tab_171969.tableoid
ON tab_171967.col1_2 = tab_171968.tableoid
AND tab_171967.col1_3 = tab_171968.col1_3
WHERE tab_171967.col1_1
ORDER BY tab_171969.col1_1 ASC;
----
project
└── inner-join (lookup table87806@table87806_col1_3_idx [as=tab_171967])
├── lookup columns are key
├── project
│ ├── inner-join (lookup table87806 [as=tab_171968])
│ │ ├── lookup columns are key
│ │ ├── select
│ │ │ ├── index-join table87806
│ │ │ │ └── scan table87806@table87806_col1_3_idx [as=tab_171969]
│ │ │ │ ├── constraint: /16/14/15: (/NULL - ]
│ │ │ │ └── flags: force-index=table87806_col1_3_idx
│ │ │ └── filters
│ │ │ └── tab_171969.col1_3 = tab_171969.tableoid
│ │ └── filters
│ │ └── tab_171968.col1_3 = tab_171969.col1_3
│ └── projections
│ └── true
└── filters (true)

0 comments on commit f970524

Please sign in to comment.