-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
100242: xform: constrain index scans on computed columns in more cases r=msirek a=msirek IN list predicates on index columns which are the inputs to computed column expressions can't currently constrain the scan if the computed columns are a prefix of the index key, e.g. ```sql CREATE TABLE t1 ( id VARCHAR(32) NOT NULL, b INT2 NOT NULL AS (CAST(substr(id, 2:::INT8, 1:::INT8) AS INT8)) VIRTUAL, CONSTRAINT pkey PRIMARY KEY (b ASC, id ASC)); -- This uses a constrained scan. SELECT * FROM t1 WHERE id IN ('12345'); -- This does not. SELECT * FROM t1 WHERE id IN ('12345', '6789'); ``` Function `computedColFilters` derives filters on computed columns by calling `findConstantFilterCols` on all required and optional filters to find the constants in single-column single-span constraints, then converts them into single-column single-span predicates on computed columns. This change introduces a new, similar function `combineComputedColFilters` which combines the steps of finding span key values and building up new predicates based on them within the same nested loops, so if the derived predicate needs to be AND'ed with the span keys they were derived from or nested under an OR term, this can be done. New terms can be generated from spans with a single key based on one or more columns, though each `FiltersItem` is processed in isolation, so there are cases `computedColFilters` can handle which `combineComputedColFilters` can't. Fixes: #100206 Fixes: #99557 Fixes: #83343 Release note (performance improvement): This adds support for constrained scans using computed columns which are part of an index when there is an IN list predicate on the columns that appears in the computed column expression. ---- opt: track columns in computed column expressions in metadata This commit adds tracking of columns present in computed column expressions to table metadata, tracked in `ColsInComputedColsExpressions`. Function `combineComputedColFilters` is updated to skip checking of constraints which do not involve columns referenced in any computed column expression of the table. Release note: None ---- sql: add optimizer_use_improved_computed_column_filters_derivation This commit adds the `optimizer_use_improved_computed_column_filters_derivation` session setting that defaults to `true`. When `true`, the optimizer will derive filters on computed columns in more cases. Previously, filters could only be derived when the expression defining the computed column involved a single column and that column was equated with a single constant value in a WHERE clause filter. Release note: None 103323: copy: fix vectorized copy handling of column families r=yuzefovich a=cucaroach Before handing off KV batches to the KV layer we sort them but when multiple column families are in use this sorting garbles the kys making reusing it for the prefix keys across families invalid. Fix by saving a copy of the keys when finishing the first family before sorting. In order to test this improve the copy-from-kvtrace command to sort the KVs so we can get consistent results from row vs. vector. Fixes: #103220 Release note (bug fix): COPY in 23.1.0 and beta versions would incorrectly encode data with multiple column families. The data must be dropped and re-imported to be encoded correctly. Co-authored-by: Mark Sirek <[email protected]> Co-authored-by: Tommy Reilly <[email protected]>
- Loading branch information
Showing
24 changed files
with
1,569 additions
and
854 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.