forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opt: fixup CTE stats on placeholder queries
During optbuilder phase we copy the initial expressions stats into the fake-rel but this value can change when placeholders are assigned so add a normalization step to do this so it happens on the assignplaceholder path. Fixes: cockroachdb#99389 Epic: none Release note: none
- Loading branch information
Showing
3 changed files
with
94 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
exec-ddl | ||
CREATE TABLE xy (x INT, y INT, INDEX (x) STORING (y)); | ||
---- | ||
|
||
exec-ddl | ||
ALTER TABLE xy INJECT STATISTICS '[ | ||
{ | ||
"columns": ["x"], | ||
"created_at": "2018-01-01 1:00:00.00000+00:00", | ||
"row_count": 100000, | ||
"distinct_count": 100000 | ||
}, | ||
{ | ||
"columns": ["y"], | ||
"created_at": "2018-01-01 1:00:00.00000+00:00", | ||
"row_count": 100000, | ||
"distinct_count": 2 | ||
} | ||
]'; | ||
---- | ||
|
||
# Regression test for #99389. | ||
assign-placeholders-opt query-args=(1) format=show-stats | ||
WITH RECURSIVE cte(a,b) AS ( | ||
(SELECT * FROM xy WHERE x = $1) | ||
UNION ALL | ||
(SELECT * FROM cte WHERE False) | ||
) | ||
SELECT * FROM cte; | ||
---- | ||
project | ||
├── columns: a:10 b:11 | ||
├── stats: [rows=10] | ||
├── recursive-c-t-e | ||
│ ├── columns: a:6 b:7 | ||
│ ├── working table binding: &1 | ||
│ ├── initial columns: x:1 y:2 | ||
│ ├── recursive columns: a:8 b:9 | ||
│ ├── stats: [rows=10] | ||
│ ├── fake-rel | ||
│ │ ├── columns: a:6 b:7 | ||
│ │ ├── cardinality: [1 - ] | ||
│ │ └── stats: [rows=1.00001] | ||
│ ├── scan xy@xy_x_idx | ||
│ │ ├── columns: x:1!null y:2 | ||
│ │ ├── constraint: /1/3: [/1 - /1] | ||
│ │ ├── stats: [rows=1.00001, distinct(1)=1, null(1)=0] | ||
│ │ └── fd: ()-->(1) | ||
│ └── values | ||
│ ├── columns: a:8!null b:9!null | ||
│ ├── cardinality: [0 - 0] | ||
│ ├── stats: [rows=0] | ||
│ ├── key: () | ||
│ └── fd: ()-->(8,9) | ||
└── projections | ||
├── a:6 [as=a:10, outer=(6)] | ||
└── b:7 [as=b:11, outer=(7)] |