Skip to content

Commit

Permalink
Merge pull request #86218 from rytaft/backport22.1-86173
Browse files Browse the repository at this point in the history
release-22.1: opt: fix error due to unsupported comparison for partitioned secondary index
  • Loading branch information
rytaft authored Aug 16, 2022
2 parents 6caa298 + b4f31ab commit 9b8a6af
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
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

0 comments on commit 9b8a6af

Please sign in to comment.