Changeset: 1d8602d97443 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1d8602d97443 Modified Files: sql/benchmarks/tpch/Tests/21-plan.stable.out sql/server/rel_partition.c Branch: default Log Message:
merged diffs (98 lines): diff --git a/sql/benchmarks/tpch/Tests/21-plan.stable.out b/sql/benchmarks/tpch/Tests/21-plan.stable.out --- a/sql/benchmarks/tpch/Tests/21-plan.stable.out +++ b/sql/benchmarks/tpch/Tests/21-plan.stable.out @@ -59,7 +59,7 @@ Ready. % .plan # table_name % rel # name % clob # type -% 1836 # length +% 379 # length top N ( | project ( | | group by ( @@ -71,22 +71,22 @@ top N ( | | | | | | | | join ( | | | | | | | | | join ( | | | | | | | | | | select ( -| | | | | | | | | | | table(sys.lineitem) [ lineitem.l_orderkey NOT NULL HASHCOL as l1.l_orderkey, lineitem.l_partkey NOT NULL as l1.l_partkey, lineitem.l_suppkey NOT NULL as l1.l_suppkey, lineitem.l_linenumber NOT NULL as l1.l_linenumber, lineitem.l_quantity NOT NULL as l1.l_quantity, lineitem.l_extendedprice NOT NULL as l1.l_extendedprice, lineitem.l_discount NOT NULL as l1.l_discount, lineitem.l_tax NOT NULL as l1.l_tax, lineitem.l_returnflag NOT NULL as l1.l_returnflag, lineitem.l_linestatus NOT NULL as l1.l_linestatus, lineitem.l_shipdate NOT NULL as l1.l_shipdate, lineitem.l_commitdate NOT NULL as l1.l_commitdate, lineitem.l_receiptdate NOT NULL as l1.l_receiptdate, lineitem.l_shipinstruct NOT NULL as l1.l_shipinstruct, lineitem.l_shipmode NOT NULL as l1.l_shipmode, lineitem.l_comment NOT NULL as l1.l_comment, lineitem.%TID% NOT NULL as l1.%TID%, lineitem.%lineitem_l_orderkey_l_linenumber_pkey NOT NULL HASHIDX as l1.%lineitem_l_orderkey_l_linenumber_pkey, lineitem.%lineitem_ l_orderkey_fkey NOT NULL JOINIDX sys.lineitem.lineitem_l_orderkey_fkey as l1.%lineitem_l_orderkey_fkey, lineitem.%lineitem_l_partkey_l_suppkey_fkey NOT NULL JOINIDX sys.lineitem.lineitem_l_partkey_l_suppkey_fkey as l1.%lineitem_l_partkey_l_suppkey_fkey ] COUNT +| | | | | | | | | | | table(sys.lineitem) [ lineitem.l_orderkey NOT NULL HASHCOL as l1.l_orderkey, lineitem.l_suppkey NOT NULL as l1.l_suppkey, lineitem.l_commitdate NOT NULL as l1.l_commitdate, lineitem.l_receiptdate NOT NULL as l1.l_receiptdate, lineitem.%lineitem_l_orderkey_fkey NOT NULL JOINIDX sys.lineitem.lineitem_l_orderkey_fkey as l1.%lineitem_l_orderkey_fkey ] COUNT | | | | | | | | | | ) [ l1.l_receiptdate NOT NULL > l1.l_commitdate NOT NULL ], | | | | | | | | | | select ( -| | | | | | | | | | | table(sys.orders) [ orders.o_orderkey NOT NULL HASHCOL , orders.o_custkey NOT NULL, orders.o_orderstatus NOT NULL, orders.o_totalprice NOT NULL, orders.o_orderdate NOT NULL, orders.o_orderpriority NOT NULL, orders.o_clerk NOT NULL, orders.o_shippriority NOT NULL, orders.o_comment NOT NULL, orders.%TID% NOT NULL, orders.%orders_o_orderkey_pkey NOT NULL HASHIDX , orders.%orders_o_custkey_fkey NOT NULL JOINIDX sys.orders.orders_o_custkey_fkey ] COUNT +| | | | | | | | | | | table(sys.orders) [ orders.o_orderstatus NOT NULL, orders.%TID% NOT NULL ] COUNT | | | | | | | | | | ) [ orders.o_orderstatus NOT NULL = char(1) "F" ] | | | | | | | | | ) [ l1.%lineitem_l_orderkey_fkey NOT NULL = orders.%TID% NOT NULL JOINIDX sys.lineitem.lineitem_l_orderkey_fkey ], -| | | | | | | | | table(sys.supplier) [ supplier.s_suppkey NOT NULL HASHCOL , supplier.s_name NOT NULL, supplier.s_address NOT NULL, supplier.s_nationkey NOT NULL, supplier.s_phone NOT NULL, supplier.s_acctbal NOT NULL, supplier.s_comment NOT NULL, supplier.%TID% NOT NULL, supplier.%supplier_s_suppkey_pkey NOT NULL HASHIDX , supplier.%supplier_s_nationkey_fkey NOT NULL JOINIDX sys.supplier.supplier_s_nationkey_fkey ] COUNT +| | | | | | | | | table(sys.supplier) [ supplier.s_suppkey NOT NULL HASHCOL , supplier.s_name NOT NULL, supplier.%supplier_s_nationkey_fkey NOT NULL JOINIDX sys.supplier.supplier_s_nationkey_fkey ] COUNT | | | | | | | | ) [ supplier.s_suppkey NOT NULL HASHCOL = l1.l_suppkey NOT NULL ], | | | | | | | | select ( -| | | | | | | | | table(sys.nation) [ nation.n_nationkey NOT NULL HASHCOL , nation.n_name NOT NULL, nation.n_regionkey NOT NULL, nation.n_comment, nation.%TID% NOT NULL, nation.%nation_n_nationkey_pkey NOT NULL HASHIDX , nation.%nation_n_regionkey_fkey NOT NULL JOINIDX sys.nation.nation_n_regionkey_fkey ] COUNT +| | | | | | | | | table(sys.nation) [ nation.n_name NOT NULL, nation.%TID% NOT NULL ] COUNT | | | | | | | | ) [ nation.n_name NOT NULL = char(25) "SAUDI ARABIA" ] | | | | | | | ) [ supplier.%supplier_s_nationkey_fkey NOT NULL = nation.%TID% NOT NULL JOINIDX sys.supplier.supplier_s_nationkey_fkey ] -| | | | | | ) [ supplier.s_suppkey NOT NULL HASHCOL , supplier.s_name NOT NULL, supplier.s_address NOT NULL, supplier.s_nationkey NOT NULL, supplier.s_phone NOT NULL, supplier.s_acctbal NOT NULL, supplier.s_comment NOT NULL, supplier.%TID% NOT NULL, supplier.%supplier_s_suppkey_pkey NOT NULL HASHIDX , supplier.%supplier_s_nationkey_fkey NOT NULL JOINIDX sys.supplier.supplier_s_nationkey_fkey, l1.l_orderkey NOT NULL HASHCOL , l1.l_partkey NOT NULL, l1.l_suppkey NOT NULL, l1.l_linenumber NOT NULL, l1.l_quantity NOT NULL, l1.l_extendedprice NOT NULL, l1.l_discount NOT NULL, l1.l_tax NOT NULL, l1.l_returnflag NOT NULL, l1.l_linestatus NOT NULL, l1.l_shipdate NOT NULL, l1.l_commitdate NOT NULL, l1.l_receiptdate NOT NULL, l1.l_shipinstruct NOT NULL, l1.l_shipmode NOT NULL, l1.l_comment NOT NULL, l1.%TID% NOT NULL, l1.%lineitem_l_orderkey_l_linenumber_pkey NOT NULL HASHIDX , l1.%lineitem_l_orderkey_fkey NOT NULL JOINIDX sys.lineitem.lineitem_l_orderkey_fkey, l1.%lineitem_l_partkey_l_suppke y_fkey NOT NULL JOINIDX sys.lineitem.lineitem_l_partkey_l_suppkey_fkey, orders.o_orderkey NOT NULL HASHCOL , orders.o_custkey NOT NULL, orders.o_orderstatus NOT NULL, orders.o_totalprice NOT NULL, orders.o_orderdate NOT NULL, orders.o_orderpriority NOT NULL, orders.o_clerk NOT NULL, orders.o_shippriority NOT NULL, orders.o_comment NOT NULL, orders.%TID% NOT NULL, orders.%orders_o_orderkey_pkey NOT NULL HASHIDX , orders.%orders_o_custkey_fkey NOT NULL JOINIDX sys.orders.orders_o_custkey_fkey, nation.n_nationkey NOT NULL HASHCOL , nation.n_name NOT NULL, nation.n_regionkey NOT NULL, nation.n_comment, nation.%TID% NOT NULL, nation.%nation_n_nationkey_pkey NOT NULL HASHIDX , nation.%nation_n_regionkey_fkey NOT NULL JOINIDX sys.nation.nation_n_regionkey_fkey, sys.identity(supplier.s_suppkey NOT NULL) HASHCOL as L3.L3 ], +| | | | | | ) [ supplier.s_suppkey NOT NULL HASHCOL , supplier.s_name NOT NULL, l1.l_orderkey NOT NULL HASHCOL , l1.l_suppkey NOT NULL, sys.identity(supplier.s_suppkey NOT NULL) HASHCOL as L3.L3 ], | | | | | | table(sys.lineitem) [ lineitem.l_orderkey NOT NULL HASHCOL as l2.l_orderkey, lineitem.l_suppkey NOT NULL as l2.l_suppkey ] COUNT | | | | | ) [ l2.l_orderkey NOT NULL HASHCOL = l1.l_orderkey NOT NULL, l2.l_suppkey NOT NULL != l1.l_suppkey NOT NULL ] -| | | | ) [ supplier.s_suppkey NOT NULL HASHCOL , supplier.s_name NOT NULL, supplier.s_address NOT NULL, supplier.s_nationkey NOT NULL, supplier.s_phone NOT NULL, supplier.s_acctbal NOT NULL, supplier.s_comment NOT NULL, supplier.%TID% NOT NULL, supplier.%supplier_s_suppkey_pkey NOT NULL HASHIDX , supplier.%supplier_s_nationkey_fkey NOT NULL JOINIDX sys.supplier.supplier_s_nationkey_fkey, l1.l_orderkey NOT NULL HASHCOL , l1.l_partkey NOT NULL, l1.l_suppkey NOT NULL, l1.l_linenumber NOT NULL, l1.l_quantity NOT NULL, l1.l_extendedprice NOT NULL, l1.l_discount NOT NULL, l1.l_tax NOT NULL, l1.l_returnflag NOT NULL, l1.l_linestatus NOT NULL, l1.l_shipdate NOT NULL, l1.l_commitdate NOT NULL, l1.l_receiptdate NOT NULL, l1.l_shipinstruct NOT NULL, l1.l_shipmode NOT NULL, l1.l_comment NOT NULL, l1.%TID% NOT NULL, l1.%lineitem_l_orderkey_l_linenumber_pkey NOT NULL HASHIDX , l1.%lineitem_l_orderkey_fkey NOT NULL JOINIDX sys.lineitem.lineitem_l_orderkey_fkey, l1.%lineitem_l_partkey_l_suppkey_fk ey NOT NULL JOINIDX sys.lineitem.lineitem_l_partkey_l_suppkey_fkey, orders.o_orderkey NOT NULL HASHCOL , orders.o_custkey NOT NULL, orders.o_orderstatus NOT NULL, orders.o_totalprice NOT NULL, orders.o_orderdate NOT NULL, orders.o_orderpriority NOT NULL, orders.o_clerk NOT NULL, orders.o_shippriority NOT NULL, orders.o_comment NOT NULL, orders.%TID% NOT NULL, orders.%orders_o_orderkey_pkey NOT NULL HASHIDX , orders.%orders_o_custkey_fkey NOT NULL JOINIDX sys.orders.orders_o_custkey_fkey, nation.n_nationkey NOT NULL HASHCOL , nation.n_name NOT NULL, nation.n_regionkey NOT NULL, nation.n_comment, nation.%TID% NOT NULL, nation.%nation_n_nationkey_pkey NOT NULL HASHIDX , nation.%nation_n_regionkey_fkey NOT NULL JOINIDX sys.nation.nation_n_regionkey_fkey, L3.L3 HASHCOL , sys.identity(supplier.s_suppkey NOT NULL) HASHCOL as L5.L5 ], +| | | | ) [ supplier.s_suppkey NOT NULL HASHCOL , supplier.s_name NOT NULL, l1.l_orderkey NOT NULL HASHCOL , l1.l_suppkey NOT NULL, sys.identity(supplier.s_suppkey NOT NULL) HASHCOL as L5.L5 ], | | | | select ( | | | | | table(sys.lineitem) [ lineitem.l_orderkey NOT NULL as L2.l_orderkey, lineitem.l_suppkey NOT NULL as L2.l_suppkey, lineitem.l_commitdate NOT NULL as L2.l_commitdate, lineitem.l_receiptdate NOT NULL as L2.l_receiptdate ] COUNT | | | | ) [ L2.l_receiptdate NOT NULL > L2.l_commitdate NOT NULL ] diff --git a/sql/server/rel_partition.c b/sql/server/rel_partition.c --- a/sql/server/rel_partition.c +++ b/sql/server/rel_partition.c @@ -91,8 +91,8 @@ find_basetables( sql_rel *rel, list *tab } } -sql_rel * -rel_partition(mvc *sql, sql_rel *rel) +static sql_rel * +_rel_partition(mvc *sql, sql_rel *rel) { list *tables = sa_list(sql->sa); /* find basetable relations */ @@ -120,3 +120,42 @@ rel_partition(mvc *sql, sql_rel *rel) } return rel; } + +static int +has_groupby(sql_rel *rel) +{ + if (rel->op == op_groupby) + return 1; + if (is_join(rel->op)) + return has_groupby(rel->l) || has_groupby(rel->r); + if ((is_select(rel->op) || is_project(rel->op)) && rel->l) + return has_groupby(rel->l); + return 0; +} + +sql_rel * +rel_partition(mvc *sql, sql_rel *rel) +{ + (void)sql; + if (rel->op == op_basetable) { + rel->flag = REL_PARTITION; + } else if ((rel->op == op_topn || rel->op == op_select) && rel->l) { + rel_partition(sql, rel->l); + } else if (is_project(rel->op) && rel->l) { + rel_partition(sql, rel->l); + } else if (rel->op == op_semi && rel->l && rel->r) { + rel_partition(sql, rel->l); + rel_partition(sql, rel->r); + } else if (rel->op == op_anti && rel->l && rel->r) { + rel_partition(sql, rel->l); + rel_partition(sql, rel->r); + } else if (is_join(rel->op)) { + if (has_groupby(rel->l) || has_groupby(rel->r)) { + rel_partition(sql, rel->l); + rel_partition(sql, rel->r); + } + else + _rel_partition(sql, rel); + } + return rel; +} _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list