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

opt: error when selecting from table with partitioned primary and secondary index with different partition column types #86168

Closed
rytaft opened this issue Aug 15, 2022 · 2 comments · Fixed by #86173
Assignees
Labels
branch-release-22.1 Used to mark GA and release blockers, technical advisories, and bugs for 22.1 C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. release-blocker Indicates a release-blocker. Use with branch-release-2x.x label to denote which branch is blocked. T-sql-queries SQL Queries Team

Comments

@rytaft
Copy link
Collaborator

rytaft commented Aug 15, 2022

Describe the problem

On 22.1.0-22.1.5, attempting to select data from a table which has different partitioning columns used for the primary and secondary indexes can cause an error. This occurs if the primary index has zone configurations applied with different regions for different partitions, and the secondary index has a different column type than the primary index for its partitioning column.

To Reproduce

Run a demo cluster with CockroachDB v22.1.5 using:

./cockroach demo --demo-locality=region=gcp-europe-west1,az=1:region=gcp-us-east1,az=2:region=gcp-us-west1,az=3 --nodes 3

Then run:

CREATE DATABASE bug;
USE bug;

CREATE TYPE region_enum AS ENUM ('EUROPE_WEST', 'US_WEST', 'US_EAST');
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)
);

CREATE UNIQUE INDEX ON "user" (col1, col2);

ALTER TABLE "user" PARTITION BY LIST (region) (
  PARTITION user_eu_west VALUES IN ('EUROPE_WEST'),
  PARTITION user_us_east VALUES IN ('US_EAST'),
  PARTITION user_us_west VALUES IN ('US_WEST'),
  PARTITION DEFAULT VALUES IN (default)
);

ALTER PARTITION user_eu_west OF TABLE "user" CONFIGURE ZONE USING
  num_replicas = 5,
  num_voters = 3,
  lease_preferences = '[[+region=gcp-europe-west1]]',
  voter_constraints = '[+region=gcp-europe-west1]';

ALTER INDEX "user"@user_col1_col2_key PARTITION BY LIST (col1) (
  PARTITION user_col1_col2_key_eu_west VALUES IN (43,32,500,600),
  PARTITION user_col1_col2_key_us_west VALUES IN (1),
  PARTITION DEFAULT VALUES IN (default)
);

After a few seconds, run:

SELECT *
FROM "user"
WHERE region = 'EUROPE_WEST';

It produces this error:

ERROR: unsupported comparison: region_enum to int
SQLSTATE: 42804

Expected behavior
This should not produce any error.

Environment:

  • CockroachDB version 22.1.5
  • Server OS: MacOS
  • Client app cockroach demo

Jira issue: CRDB-18609

@rytaft rytaft added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Aug 15, 2022
@blathers-crl blathers-crl bot added the T-sql-queries SQL Queries Team label Aug 15, 2022
@rytaft rytaft self-assigned this Aug 15, 2022
@rytaft rytaft added release-blocker Indicates a release-blocker. Use with branch-release-2x.x label to denote which branch is blocked. branch-release-22.1 Used to mark GA and release blockers, technical advisories, and bugs for 22.1 labels Aug 15, 2022
craig bot pushed a commit that referenced this issue Aug 16, 2022
86078: sql/stats: generate statistics forecasts r=rytaft,yuzefovich a=michae2

**sql/stats: use nil eval.Context as CompareContext when forecasting**

When forecasting table statistics, we don't need a full *eval.Context.
We can simply use a nil *eval.Context as a tree.CompareContext. This
means we don't have to plumb an eval.Context into the stats cache.

Assists: #79872

Release note: None

**sql/stats: generate statistics forecasts in the stats cache**

As of this commit, we now try to generate statistics forecasts for every
column of every table. This happens whenever statistics are loaded into
or refreshed in the stats cache. We use only the forecasts that fit the
historical collected statistics very well, meaning we have high
confidence in their accuracy.

Fixes: #79872

Release note (performance improvement): Enable table statistics
forecasts, which predict future statistics based on historical collected
statistics. Forecasts help the optimizer produce better plans for
queries that read data modified after the latest statistics collection.
We use only the forecasts that fit the historical collected statistics
very well, meaning we have high confidence in their accuracy. Forecasts
can be viewed using `SHOW STATISTICS FOR TABLE ... WITH FORECAST`.

**sql: show forecasted stats time in EXPLAIN**

When using statistics forecasts, add the forecast time (which could be
in the future) to EXPLAIN output. This both indicates that forecasts are
in use, and gives us an idea of how up-to-date / ahead they are.

Assists: #79872

Release note: None

**sql/opt: add tests for statistics forecasts**

Add a few simple testcases for usage of statistics forecasts by the
optimizer.

Assists: #79872

Release note: None

---

Release justification: Enable feature before we get too far into
stability period.

86137: sql: use DelRange with tombstone in `force_delete_table_data` r=ajwerner a=ajwerner

Fixes #85754

Release justification: minor change needed to adopt MVCC bulk ops fully

Release note: None

86160: colexecerror: do not annotate the context canceled error r=yuzefovich a=yuzefovich

This commit makes it so that the context canceled error doesn't get
annotated with an assertion failure when it doesn't have a valid PG
code. This makes sure that the sentry issues don't get filed for the
context canceled errors - they are expected to occur.

Fixes: #82947

Release note: None

Release justification: bug fix.

86164: sql: deflake TestRoleOptionsMigration15000User r=ajwerner a=RichardJCai

Previously it was flakey because we always assumed the first user created
had ID 100, however this is not the case due to transaction failures.

Release note: None

Release justification: test only

86173: opt: fix error due to unsupported comparison for partitioned secondary index r=rytaft a=rytaft

This commit fixes a bug where we were attempting to find the locality of the
partitions in a secondary index, but we passed the incorrect index ordinal to
the function `IndexPartitionLocality`.

Fixes #86168

Release justification: Category 3: Fixes for high-priority or high-severity bugs in existing functionality

Release note (bug fix): Fixed a bug that existed on v22.1.0-v22.1.5, where
attempting to select data from a table that had different partitioning columns
used for the primary and secondary indexes could cause an error. This occured
if the primary index had zone configurations applied to the index partitions
with different regions for different partitions, and the secondary index had a
different column type than the primary index for its partitioning column(s).

Co-authored-by: Michael Erickson <[email protected]>
Co-authored-by: Andrew Werner <[email protected]>
Co-authored-by: Yahor Yuzefovich <[email protected]>
Co-authored-by: richardjcai <[email protected]>
Co-authored-by: Rebecca Taft <[email protected]>
@craig craig bot closed this as completed in 6b452bc Aug 16, 2022
rytaft added a commit to rytaft/cockroach that referenced this issue Aug 16, 2022
…y index

This commit fixes a bug where we were attempting to find the locality of the
partitions in a secondary index, but we passed the incorrect index ordinal to
the function IndexPartitionLocality.

Fixes cockroachdb#86168

Release note (bug fix): Fixed a bug that existed on v22.1.0-v22.1.5, where
attempting to select data from a table that had different partitioning columns
used for the primary and secondary indexes could cause an error. This occured
if the primary index had zone configurations applied to the index partitions
with different regions for different partitions, and the secondary index had a
different column type than the primary index for its partitioning column(s).
@rytaft
Copy link
Collaborator Author

rytaft commented Aug 16, 2022

Reopening until #86218 is merged

@rytaft rytaft reopened this Aug 16, 2022
@rytaft
Copy link
Collaborator Author

rytaft commented Aug 16, 2022

#86218 is merged, closing

@rytaft rytaft closed this as completed Aug 16, 2022
@mgartner mgartner moved this to Done in SQL Queries Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
branch-release-22.1 Used to mark GA and release blockers, technical advisories, and bugs for 22.1 C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. release-blocker Indicates a release-blocker. Use with branch-release-2x.x label to denote which branch is blocked. T-sql-queries SQL Queries Team
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant