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-22.1: opt: fix error due to unsupported comparison for partitioned secondary index #86218

Merged
merged 1 commit into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/sql/opt/xform/select_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func (c *CustomFuncs) GenerateConstrainedScans(
iter.ForEach(func(index cat.Index, filters memo.FiltersExpr, indexCols opt.ColSet, isCovering bool, constProj memo.ProjectionsExpr) {

// A structure describing which index partitions are local to the gateway region
prefixSorter, _ := tabMeta.IndexPartitionLocality(scanPrivate.Index, index, c.e.evalCtx)
prefixSorter, _ := tabMeta.IndexPartitionLocality(index.Ordinal(), index, c.e.evalCtx)

// Build Constraints to scan a subset of the table Spans.
if partitionFilters, remainingFilters, combinedConstraint, ok =
Expand Down
57 changes: 57 additions & 0 deletions pkg/sql/opt/xform/testdata/rules/select
Original file line number Diff line number Diff line change
Expand Up @@ -2179,6 +2179,63 @@ index-join e
├── key: (1)
└── fd: (1)-->(2,4)

# Regression test for #86168. Selecting from a table with a partitioned
# primary and secondary index, where the primary index is partitioned by
# region and the secondary index is partitioned by another column, should
# not cause an error.
exec-ddl
CREATE TYPE region_enum AS ENUM ('AP_SOUTHEAST', 'CA_CENTRAL', 'US_EAST');
----

exec-ddl
CREATE TABLE "user" (
region region_enum NOT NULL,
id uuid NOT NULL DEFAULT uuid_generate_v4(),
col1 int2 AS (col2::int2) VIRTUAL,
col2 varchar NOT NULL,
PRIMARY KEY (region, id),
UNIQUE (col1, col2) PARTITION BY LIST (col1) (
PARTITION user_col1_col2_key_ap_southeast VALUES IN (43,32),
PARTITION user_col1_col2_key_ca_central VALUES IN (1),
PARTITION DEFAULT VALUES IN (default)
)
) PARTITION BY LIST (region) (
PARTITION user_ap_southeast VALUES IN ('AP_SOUTHEAST'),
PARTITION user_us_east VALUES IN ('US_EAST'),
PARTITION user_ca_central VALUES IN ('CA_CENTRAL'),
PARTITION DEFAULT VALUES IN (default)
);
----

exec-ddl
ALTER PARTITION user_ap_southeast OF TABLE "user" CONFIGURE ZONE USING
num_replicas = 5,
num_voters = 3,
lease_preferences = '[[+region=ap-southeast-2]]',
voter_constraints = '[+region=ap-southeast-2]';
----

opt locality=(region=ap-southeast-2)
SELECT *
FROM "user"
WHERE region = 'AP_SOUTHEAST';
----
project
├── columns: region:1!null id:2!null col1:3!null col2:4!null
├── immutable
├── key: (2)
├── fd: ()-->(1), (2)-->(4), (4)-->(3)
├── distribution: ap-southeast-2
├── scan user
│ ├── columns: region:1!null id:2!null col2:4!null
│ ├── constraint: /1/2: [/'AP_SOUTHEAST' - /'AP_SOUTHEAST']
│ ├── immutable
│ ├── key: (2)
│ ├── fd: ()-->(1), (2)-->(4)
│ └── distribution: ap-southeast-2
└── projections
└── col2:4::INT2 [as=col1:3, outer=(4), immutable]

# --------------------------------------------------
# GenerateInvertedIndexScans
# --------------------------------------------------
Expand Down