Skip to content

Commit

Permalink
fix(sql): don't fuse subsequent filter operations
Browse files Browse the repository at this point in the history
  • Loading branch information
kszucs committed Apr 26, 2024
1 parent c4da866 commit 61a5de9
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 131 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
WITH "t1" AS (
SELECT
"t0"."a",
"t0"."b"
FROM "my_table" AS "t0"
WHERE
"t0"."a" < CAST(100 AS TINYINT)
)
SELECT
"t0"."a",
"t0"."b"
FROM "my_table" AS "t0"
WHERE
"t0"."a" < CAST(100 AS TINYINT)
AND "t0"."a" = (
SELECT
MAX("t1"."a") AS "Max(a)"
FROM (
"t4"."a",
"t4"."b"
FROM (
SELECT
"t2"."a",
"t2"."b"
FROM "t1" AS "t2"
WHERE
"t2"."a" = (
SELECT
"t0"."a",
"t0"."b"
FROM "my_table" AS "t0"
WHERE
"t0"."a" < CAST(100 AS TINYINT)
) AS "t1"
)
AND "t0"."b" = 'a'
MAX("t2"."a") AS "Max(a)"
FROM "t1" AS "t2"
)
) AS "t4"
WHERE
"t4"."b" = 'a'
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
WITH "t1" AS (
SELECT
"t0"."a",
"t0"."b" * CAST(2 AS TINYINT) AS "b2"
FROM "my_table" AS "t0"
WHERE
"t0"."a" < CAST(100 AS TINYINT)
)
SELECT
"t0"."a",
"t0"."b" * CAST(2 AS TINYINT) AS "b2"
FROM "my_table" AS "t0"
"t2"."a",
"t2"."b2"
FROM "t1" AS "t2"
WHERE
"t0"."a" < CAST(100 AS TINYINT)
AND "t0"."a" = (
"t2"."a" = (
SELECT
MAX("t1"."a") AS "Max(a)"
FROM (
SELECT
"t0"."a",
"t0"."b" * CAST(2 AS TINYINT) AS "b2"
FROM "my_table" AS "t0"
WHERE
"t0"."a" < CAST(100 AS TINYINT)
) AS "t1"
MAX("t2"."a") AS "Max(a)"
FROM "t1" AS "t2"
)
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
WITH "t1" AS (
SELECT
"t0"."a",
"t0"."b" * CAST(2 AS TINYINT) AS "b2"
FROM "my_table" AS "t0"
WHERE
"t0"."a" < CAST(100 AS TINYINT)
)
SELECT
"t0"."a",
"t0"."b" * CAST(2 AS TINYINT) AS "b2"
FROM "my_table" AS "t0"
"t2"."a",
"t2"."b2"
FROM "t1" AS "t2"
WHERE
"t0"."a" < CAST(100 AS TINYINT)
AND "t0"."a" = (
"t2"."a" = (
SELECT
MAX("t1"."a") AS "Max(a)"
FROM (
SELECT
"t0"."a",
"t0"."b" * CAST(2 AS TINYINT) AS "b2"
FROM "my_table" AS "t0"
WHERE
"t0"."a" < CAST(100 AS TINYINT)
) AS "t1"
MAX("t2"."a") AS "Max(a)"
FROM "t1" AS "t2"
)
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
SELECT
"t0"."double_col",
"t0"."string_col",
"t0"."int_col",
"t0"."float_col"
FROM "functional_alltypes" AS "t0"
"t1"."double_col",
"t1"."string_col",
"t1"."int_col",
"t1"."float_col"
FROM (
SELECT
"t0"."double_col",
"t0"."string_col",
"t0"."int_col",
"t0"."float_col"
FROM "functional_alltypes" AS "t0"
WHERE
"t0"."double_col" > CAST(3.14 AS DOUBLE) AND CONTAINS("t0"."string_col", 'foo')
) AS "t1"
WHERE
"t0"."double_col" > CAST(3.14 AS DOUBLE)
AND CONTAINS("t0"."string_col", 'foo')
AND (
(
(
(
"t0"."int_col" - CAST(1 AS TINYINT)
) = CAST(0 AS TINYINT)
)
OR (
"t0"."float_col" <= CAST(1.34 AS DOUBLE)
)
"t1"."int_col" - CAST(1 AS TINYINT)
) = CAST(0 AS TINYINT)
)
OR (
"t1"."float_col" <= CAST(1.34 AS DOUBLE)
)
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
WITH "t1" AS (
SELECT
"t0"."a",
"t0"."b"
FROM "my_table" AS "t0"
WHERE
"t0"."a" < CAST(100 AS TINYINT)
)
SELECT
"t0"."a",
"t0"."b"
FROM "my_table" AS "t0"
"t2"."a",
"t2"."b"
FROM "t1" AS "t2"
WHERE
"t0"."a" < CAST(100 AS TINYINT)
AND "t0"."a" = (
"t2"."a" = (
SELECT
MAX("t1"."a") AS "Max(a)"
FROM (
SELECT
"t0"."a",
"t0"."b"
FROM "my_table" AS "t0"
WHERE
"t0"."a" < CAST(100 AS TINYINT)
) AS "t1"
MAX("t2"."a") AS "Max(a)"
FROM "t1" AS "t2"
)
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
SELECT
"t1"."g",
SUM("t1"."foo") AS "foo total"
"t2"."g",
SUM("t2"."foo") AS "foo total"
FROM (
SELECT
"t0"."a",
"t0"."b",
"t0"."c",
"t0"."d",
"t0"."e",
"t0"."f",
"t0"."g",
"t0"."h",
"t0"."i",
"t0"."j",
"t0"."k",
"t0"."a" + "t0"."b" AS "foo"
FROM "alltypes" AS "t0"
"t1"."a",
"t1"."b",
"t1"."c",
"t1"."d",
"t1"."e",
"t1"."f",
"t1"."g",
"t1"."h",
"t1"."i",
"t1"."j",
"t1"."k",
"t1"."foo"
FROM (
SELECT
"t0"."a",
"t0"."b",
"t0"."c",
"t0"."d",
"t0"."e",
"t0"."f",
"t0"."g",
"t0"."h",
"t0"."i",
"t0"."j",
"t0"."k",
"t0"."a" + "t0"."b" AS "foo"
FROM "alltypes" AS "t0"
WHERE
"t0"."f" > CAST(0 AS TINYINT)
) AS "t1"
WHERE
"t0"."f" > CAST(0 AS TINYINT) AND "t0"."g" = 'bar'
) AS "t1"
"t1"."g" = 'bar'
) AS "t2"
GROUP BY
1
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
SELECT
"t1"."g",
SUM("t1"."foo") AS "foo total"
"t2"."g",
SUM("t2"."foo") AS "foo total"
FROM (
SELECT
"t0"."a",
"t0"."b",
"t0"."c",
"t0"."d",
"t0"."e",
"t0"."f",
"t0"."g",
"t0"."h",
"t0"."i",
"t0"."j",
"t0"."k",
"t0"."a" + "t0"."b" AS "foo"
FROM "alltypes" AS "t0"
"t1"."a",
"t1"."b",
"t1"."c",
"t1"."d",
"t1"."e",
"t1"."f",
"t1"."g",
"t1"."h",
"t1"."i",
"t1"."j",
"t1"."k",
"t1"."foo"
FROM (
SELECT
"t0"."a",
"t0"."b",
"t0"."c",
"t0"."d",
"t0"."e",
"t0"."f",
"t0"."g",
"t0"."h",
"t0"."i",
"t0"."j",
"t0"."k",
"t0"."a" + "t0"."b" AS "foo"
FROM "alltypes" AS "t0"
WHERE
"t0"."f" > CAST(0 AS TINYINT)
) AS "t1"
WHERE
"t0"."f" > CAST(0 AS TINYINT) AND (
"t0"."a" + "t0"."b"
) < CAST(10 AS TINYINT)
) AS "t1"
"t1"."foo" < CAST(10 AS TINYINT)
) AS "t2"
GROUP BY
1
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
SELECT
"t0"."a",
"t0"."b",
"t0"."c",
"t0"."d",
"t0"."e",
"t0"."f",
"t0"."g",
"t0"."h",
"t0"."i",
"t0"."j",
"t0"."k",
"t0"."a" + "t0"."b" AS "foo"
FROM "alltypes" AS "t0"
"t1"."a",
"t1"."b",
"t1"."c",
"t1"."d",
"t1"."e",
"t1"."f",
"t1"."g",
"t1"."h",
"t1"."i",
"t1"."j",
"t1"."k",
"t1"."foo"
FROM (
SELECT
"t0"."a",
"t0"."b",
"t0"."c",
"t0"."d",
"t0"."e",
"t0"."f",
"t0"."g",
"t0"."h",
"t0"."i",
"t0"."j",
"t0"."k",
"t0"."a" + "t0"."b" AS "foo"
FROM "alltypes" AS "t0"
WHERE
"t0"."f" > CAST(0 AS TINYINT)
) AS "t1"
WHERE
"t0"."f" > CAST(0 AS TINYINT) AND "t0"."g" = 'bar'
"t1"."g" = 'bar'
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ WHERE
EXISTS(
SELECT
1
FROM "purchases" AS "t1"
FROM (
SELECT
"t1"."item_id",
"t1"."user_id",
"t1"."price",
"t1"."ts"
FROM "purchases" AS "t1"
WHERE
"t1"."ts" > '2015-08-15'
) AS "t2"
WHERE
"t1"."ts" > '2015-08-15' AND "t0"."user_id" = "t1"."user_id"
"t0"."user_id" = "t2"."user_id"
)
Loading

0 comments on commit 61a5de9

Please sign in to comment.