123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- # Copyright Materialize, Inc. and contributors. All rights reserved.
- #
- # Use of this software is governed by the Business Source License
- # included in the LICENSE file at the root of this repository.
- #
- # As of the Change Date specified in that file, in accordance with
- # the Business Source License, use of this software will be governed
- # by the Apache License, Version 2.0.
- # This file contains tests for the Scalar CSE transforms.
- statement ok
- CREATE TABLE x (a string, b int not null)
- query T multiline
- EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR SELECT b*b*b, b*b FROM x
- ----
- Explained Query:
- Project (#3, #2) // { arity: 2 }
- Map ((#1{b} * #1{b}), (#2 * #1{b})) // { arity: 4 }
- ReadStorage materialize.public.x // { arity: 2 }
- Source materialize.public.x
- Target cluster: quickstart
- EOF
- query T multiline
- EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR SELECT b*b*b, b*b+1 FROM x
- ----
- Explained Query:
- Project (#3, #4) // { arity: 2 }
- Map ((#1{b} * #1{b}), (#2 * #1{b}), (#2 + 1)) // { arity: 5 }
- ReadStorage materialize.public.x // { arity: 2 }
- Source materialize.public.x
- Target cluster: quickstart
- EOF
- query T multiline
- EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR SELECT
- a::json->'Field1',
- a::json->'Field2',
- a::json->'Field3'
- FROM x
- ----
- Explained Query:
- Project (#3..=#5) // { arity: 3 }
- Map (text_to_jsonb(#0{a}), (#2 -> "Field1"), (#2 -> "Field2"), (#2 -> "Field3")) // { arity: 6 }
- ReadStorage materialize.public.x // { arity: 2 }
- Source materialize.public.x
- Target cluster: quickstart
- EOF
- query T multiline
- EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR SELECT
- a::json->'Field1'->'Foo',
- a::json->'Field1'->'Bar',
- a::json->'Field2'->'Baz',
- a::json->'Field2'->'Quux'->'Zorb'
- FROM x
- ----
- Explained Query:
- Project (#4, #5, #7, #8) // { arity: 4 }
- Map (text_to_jsonb(#0{a}), (#2 -> "Field1"), (#3 -> "Foo"), (#3 -> "Bar"), (#2 -> "Field2"), (#6 -> "Baz"), ((#6 -> "Quux") -> "Zorb")) // { arity: 9 }
- ReadStorage materialize.public.x // { arity: 2 }
- Source materialize.public.x
- Target cluster: quickstart
- EOF
- # Ensure we don't inline if-guarded expressions
- query T multiline
- EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR SELECT
- CASE WHEN b = 0 THEN 0 ELSE 1/b END,
- CASE WHEN b != 0 THEN 1/b ELSE 0 END
- FROM x
- ----
- Explained Query:
- Project (#2, #3) // { arity: 2 }
- Map (case when (#1{b} = 0) then 0 else (1 / #1{b}) end, case when (#1{b} != 0) then (1 / #1{b}) else 0 end) // { arity: 4 }
- ReadStorage materialize.public.x // { arity: 2 }
- Source materialize.public.x
- Target cluster: quickstart
- EOF
- # Ensure we update columns references in if-guarded expressions
- query T multiline
- EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR SELECT
- CASE WHEN b = 0 THEN 0 ELSE 1/b END,
- CASE WHEN b != 0 THEN 1/b ELSE 0 END
- FROM
- (SELECT b/2 as b FROM x)
- ----
- Explained Query:
- Project (#3, #4) // { arity: 2 }
- Map ((#1{b} / 2), case when (#2{b} = 0) then 0 else (1 / #2) end, case when (#2{b} != 0) then (1 / #2) else 0 end) // { arity: 5 }
- ReadStorage materialize.public.x // { arity: 2 }
- Source materialize.public.x
- Target cluster: quickstart
- EOF
- # Regression test for https://github.com/MaterializeInc/database-issues/issues/6372
- statement ok
- CREATE TABLE t(x int);
- query T multiline
- EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR select * from t where 2*x + 2*x > 0
- ----
- Explained Query:
- Project (#0{x})
- Filter ((#1 + #1) > 0)
- Map ((2 * #0{x}))
- ReadStorage materialize.public.t
- Source materialize.public.t
- filter=(((#1 + #1) > 0))
- map=((2 * #0{x}))
- Target cluster: quickstart
- EOF
- query T multiline
- EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR select * from t where 2*x + 2*x + 2*x > 0
- ----
- Explained Query:
- Project (#0{x})
- Filter (((#1 + #1) + #1) > 0)
- Map ((2 * #0{x}))
- ReadStorage materialize.public.t
- Source materialize.public.t
- filter=((((#1 + #1) + #1) > 0))
- map=((2 * #0{x}))
- Target cluster: quickstart
- EOF
- query T multiline
- EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR select * from t where 2*x + 5*x + 2*x > 0
- ----
- Explained Query:
- Project (#0{x})
- Filter (((#1 + (5 * #0{x})) + #1) > 0)
- Map ((2 * #0{x}))
- ReadStorage materialize.public.t
- Source materialize.public.t
- filter=((((#1 + (5 * #0{x})) + #1) > 0))
- map=((2 * #0{x}))
- Target cluster: quickstart
- EOF
|