forked from duckdb/duckdb
-
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.
No pushing filters below projections that cast to a lower logical typ…
…e id (duckdb#13617) Fixes duckdb#12577 It was also important to realize that if the cast is to a higher logical type, than the filter can be pushed down, since all values of the lower logical type can always be cast to the higher logical type (i.e all INT values can be cast to VARCHAR values). The other way around, however, does not work, and when such a cast occurs (i.e VARCHAR to INT) the filter cannot be pushed down.
- Loading branch information
Showing
6 changed files
with
99 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# name: test/sql/optimizer/test_no_pushdown_cast_into_cte.test | ||
# description: No Pushdown cast into cte | ||
# group: [optimizer] | ||
|
||
statement ok | ||
pragma explain_output='optimized_only'; | ||
|
||
query II | ||
WITH t(a, b) AS ( | ||
SELECT a :: int, b :: int | ||
FROM (VALUES | ||
('1', '4'), | ||
('5', '3'), | ||
('2', '*'), | ||
('3', '8'), | ||
('7', '*')) AS _(a, b) | ||
WHERE position('*' in b) = 0 | ||
) | ||
SELECT a, b | ||
FROM t | ||
WHERE a < b; | ||
---- | ||
1 4 | ||
3 8 | ||
|
||
|
||
# check filter is above projection that casts the varchar to int | ||
query II | ||
EXPLAIN WITH t(a, b) AS ( | ||
SELECT a :: int, b :: int | ||
FROM (VALUES | ||
('1', '4'), | ||
('5', '3'), | ||
('2', '*'), | ||
('3', '8'), | ||
('7', '*')) AS _(a, b) | ||
WHERE position('*' in b) = 0 | ||
) | ||
SELECT a, b | ||
FROM t | ||
WHERE a < b; | ||
---- | ||
logical_opt <REGEX>:.*FILTER.*CAST\(a AS INTEGER.*<.*b AS INTEGER\).*PROJECTION.*FILTER.*position.* | ||
|
||
|
||
# INT can always be cast to varchar, so the filter a[1] = '1' | ||
# can be pushed down | ||
query II | ||
with t(a, b) as ( | ||
select a :: varchar, b :: varchar | ||
FROM VALUES | ||
(1, 2), | ||
(3, 3), | ||
(5, 6), | ||
(7, 6) as | ||
_(a, b) where a <= b | ||
) select a, b from t where a[1] = '1'; | ||
---- | ||
1 2 | ||
|
||
|
||
# we should not see two filters, since the filter can be pushed to just above the column data scan | ||
query II | ||
explain with t(a, b) as ( | ||
select a :: varchar, b :: varchar | ||
FROM VALUES | ||
(1, 2), | ||
(3, 3), | ||
(5, 6), | ||
(7, 6) as | ||
_(a, b) where a <= b | ||
) select a, b from t where a[1] = '1'; | ||
---- | ||
logical_opt <!REGEX>:.*FILTER.*PROJECTION.*FILTER.* |