-
Notifications
You must be signed in to change notification settings - Fork 2k
fix: Optimize !~ '.*' case to col IS NOT NULL AND Boolean(NULL) instead of Eq ""
#20702
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
base: main
Are you sure you want to change the base?
Changes from all commits
1ed89c9
e0341ed
65d16c1
f62da0b
58e080c
35c6947
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,10 +44,10 @@ query TT | |
| explain select b from t where b !~ '.*' | ||
| ---- | ||
| logical_plan | ||
| 01)Filter: t.b = Utf8View("") | ||
| 01)Filter: t.b IS NOT NULL AND Boolean(NULL) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should add a test that actually executes Specifically like this (the ::text is needed for postgres): -- Reproducer for regex simplification of `col !~ '.*'`
-- Input values: 'foo', '', NULL
WITH t(col) AS (
VALUES
('foo'::text),
(''::text),
(NULL::text)
)
SELECT
col,
col !~ '.*' AS not_match_dot_star
FROM t;
Should result in +------+-----------------+
| a | baseline_result |
+------+-----------------+
| foo | false |
| | false |
| NULL | NULL |
+------+-----------------+Here is what current datafusion does andrewlamb@Andrews-MacBook-Pro-3:~/Software/datafusion2$ datafusion-cli
DataFusion CLI v52.1.0
> WITH t(col) AS (
VALUES
('foo'::text),
(''::text),
(NULL::text)
)
SELECT
col,
col !~ '.*' AS not_match_dot_star
FROM t;
+------+--------------------+
| col | not_match_dot_star |
+------+--------------------+
| foo | false |
| | true |
| NULL | NULL |
+------+--------------------+
3 row(s) fetched.
Elapsed 0.038 seconds.Here is what postgres says postgres=# WITH t(col) AS (
VALUES
('foo'::text),
(''::text),
(NULL::text)
)
SELECT
col,
col !~ '.*' AS not_match_dot_star
FROM t;
col | not_match_dot_star
-----+--------------------
foo | f
| f
|
(3 rows)I think this branch will not get the right value for |
||
| 02)--TableScan: t projection=[b] | ||
| physical_plan | ||
| 01)FilterExec: b@0 = | ||
| 01)FilterExec: b@0 IS NOT NULL AND NULL | ||
| 02)--DataSourceExec: partitions=1, partition_sizes=[1] | ||
|
|
||
| query T | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this case should be
is_nullrather thanis_not_nullI think this because when
leftis null, The expressionnull !~ '.*'should also evaluate tonullHowever, as written (
col IS NOT NULL AND NULL) will evaluateIf the transformation is
col IS NULL AND NULL🤯 then:As expected