Skip to content
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

Tree of SELECTs -> multi-statement combination of SELECT and CREATE TABLE tN AS SELECT #15

Open
carlopi opened this issue Aug 7, 2023 · 0 comments

Comments

@carlopi
Copy link
Contributor

carlopi commented Aug 7, 2023

Idea (that might be wrong, unsure) is that a single statement is a tree of SELECTs, can be transformed in an equivalent (but rendered bottom-up) tree of CREATE TABLE t{1....N} AS SELECT.

Example:

SELECT CASE  WHEN (((ref_0.p_brand ~~~ ref_0.p_container) OR EXISTS(SELECT ref_1.o_custkey AS c0, ref_0.p_comment AS c1 FROM main.orders AS ref_1 INNER JOIN main.part AS ref_2 ON (EXISTS(SELECT subq_0.c1 AS c0, subq_0.c0 AS c1, ref_3.p_size AS c2, ref_0.p_mfgr AS c3, (SELECT s_suppkey FROM main.supplier LIMIT 1 OFFSET 1) AS c4 FROM main.part AS ref_3 , (SELECT ref_1.o_custkey AS c0, ref_1.o_comment AS c1 FROM main.customer AS ref_4 WHERE (ref_4.c_name IS NULL)) AS subq_0 WHERE (ref_0.p_container ~~ ref_1.o_orderstatus) LIMIT 104)) WHERE EXISTS(SELECT ref_2.p_mfgr AS c0, (SELECT s_name FROM main.supplier LIMIT 1 OFFSET 3) AS c1, ref_1.o_clerk AS c2, ref_0.p_partkey AS c3, (SELECT r_regionkey FROM main.region LIMIT 1 OFFSET 6) AS c4, ref_1.o_orderstatus AS c5, ref_5.r_comment AS c6, ref_5.r_comment AS c7, ref_5.r_regionkey AS c8, ref_2.p_size AS c9, ref_1.o_orderkey AS c10, ref_2.p_mfgr AS c11, 78 AS c12, ref_1.o_custkey AS c13, (SELECT n_regionkey FROM main.nation LIMIT 1 OFFSET 1) AS c14, ref_2.p_container AS c15, ref_5.r_comment AS c16, ref_0.p_comment AS c17, ref_5.r_regionkey AS c18, ref_1.o_orderdate AS c19, ref_0.p_brand AS c20 FROM main.region AS ref_5 WHERE 1 LIMIT 74) LIMIT 121))) THEN (ref_0.p_type) ELSE ref_0.p_type END AS c3, CASE  WHEN ((ref_0.p_size IS NULL)) THEN (ref_0.p_name) ELSE ref_0.p_name END AS c4 FROM main.part AS ref_0 LIMIT 110

(from issue #460 I think)
can likely rendered as

CREATE TABLE t0 AS SELECT n_regionkey FROM main.nation LIMIT 1 OFFSET 1;
CREATE TABLE t1 AS SELECT r_regionkey FROM main.region LIMIT 1 OFFSET 6) AS c4, ref_1.o_orderstatus AS c5, ref_5.r_comment AS c6, ref_5.r_comment AS c7, ref_5.r_regionkey AS c8, ref_2.p_size AS c9, ref_1.o_orderkey AS c10, ref_2.p_mfgr AS c11, 78 AS c12, ref_1.o_custkey AS c13, (SELECT t0) AS c14, ref_2.p_container AS c15, ref_5.r_comment AS c16, ref_0.p_comment AS c17, ref_5.r_regionkey AS c18, ref_1.o_orderdate AS c19, ref_0.p_brand AS c20 FROM main.region AS ref_5 WHERE 1 LIMIT 74;
SELECT CASE  WHEN .... (SELECT t1) .........;

or even adding storage and checkpoints in the middle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant