Changeset: 12a93f353cf8 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=12a93f353cf8
Modified Files:
        sql/server/rel_optimizer.c
        sql/test/mergetables/Tests/part-elim.stable.out
        sql/test/remote/Tests/partition_elim.stable.out
Branch: Jul2017
Log Message:

remove unused columns in merge tables


diffs (truncated from 732 to 300 lines):

diff --git a/sql/server/rel_optimizer.c b/sql/server/rel_optimizer.c
--- a/sql/server/rel_optimizer.c
+++ b/sql/server/rel_optimizer.c
@@ -5962,13 +5962,7 @@ rel_remove_unused(mvc *sql, sql_rel *rel
                return rel;
 
        switch(rel->op) {
-       case op_basetable: {
-               sql_table *t = rel->l;
-
-               if (t && (isMergeTable(t) || isReplicaTable(t))) 
-                       return rel;
-       }
-               /* fall through */
+       case op_basetable:
        case op_table:
                if (rel->exps) {
                        node *n;
@@ -7679,6 +7673,22 @@ exp_range_overlap( mvc *sql, sql_exp *e,
        return 1;
 }
 
+static sql_rel *
+rel_rename_part(mvc *sql, sql_rel *p, char *tname, sql_table *mt) 
+{
+       node *n, *m;
+
+       assert(list_length(p->exps) >= list_length(mt->columns.set));
+       for( n = p->exps->h, m = mt->columns.set->h; n && m; n = n->next, m = 
m->next) {
+               sql_exp *ne = n->data;
+               sql_column *c = m->data;
+
+               exp_setname(sql->sa, ne, tname, c->base.name);
+       }
+       return p;
+}
+
+
 /* rewrite merge tables into union of base tables and call optimizer again */
 static sql_rel *
 rel_merge_table_rewrite(int *changes, mvc *sql, sql_rel *rel)
@@ -7771,8 +7781,9 @@ rel_merge_table_rewrite(int *changes, mv
                                        sql_part *pd = nt->data;
                                        sql_table *pt = find_sql_table(t->s, 
pd->base.name);
                                        sql_rel *prel = rel_basetable(sql, pt, 
tname);
-                                       node *n, *m;
+                                       node *n;
                                        int skip = 0, j;
+                                       list *exps = NULL;
 
                                        /* do not include empty partitions */
                                        if ((nrel || nt->next) && 
@@ -7780,14 +7791,23 @@ rel_merge_table_rewrite(int *changes, mv
                                                continue;
                                        }
 
+                                       prel = rel_rename_part(sql, prel, 
tname, t);
+
                                        MT_lock_set(&prel->exps->ht_lock);
                                        prel->exps->ht = NULL;
                                        MT_lock_unset(&prel->exps->ht_lock);
-                                       for (n = rel->exps->h, m = 
prel->exps->h, j=0; n && m && (!skip || first); n = n->next, m = m->next, j++) {
-                                               sql_exp *e = n->data;
-                                               sql_exp *ne = m->data;
+                                       exps = sa_list(sql->sa);
+                                       for (n = rel->exps->h, j=0; n && (!skip 
|| first); n = n->next, j++) {
+                                               sql_exp *e = n->data, *ne = 
NULL;
                                                int i;
 
+                                               if (e)
+                                                       ne = 
exps_bind_column2(prel->exps, e->l, e->r);
+                                               if (!e || !ne) {
+                                                       (*changes)--;
+                                                       assert(0);
+                                                       return rel;
+                                               }
                                                if (pt && isTable(pt) && 
pt->access == TABLE_READONLY && sel && (nrel || nt->next) && 
                                                        ((first && 
(i=find_col_exp(cols, e)) != -1) ||
                                                        (!first && pos[j] > 
0))) {
@@ -7823,12 +7843,9 @@ rel_merge_table_rewrite(int *changes, mv
                                                }
                                                assert(e->type == e_column);
                                                exp_setname(sql->sa, ne, e->l, 
e->r);
-                                               /* make sure we don't include 
additional indices */
-                                               if (!n->next && m->next) {
-                                                       m->next = NULL;
-                                                       prel->exps->cnt = 
rel->exps->cnt;
-                                               }
+                                               append(exps, ne);
                                        }
+                                       prel->exps = exps;
                                        first = 0;
                                        if (!skip) {
                                                append(tables, prel);
diff --git a/sql/test/mergetables/Tests/part-elim.stable.out 
b/sql/test/mergetables/Tests/part-elim.stable.out
--- a/sql/test/mergetables/Tests/part-elim.stable.out
+++ b/sql/test/mergetables/Tests/part-elim.stable.out
@@ -56,16 +56,16 @@ Ready.
 % .plan # table_name
 % rel # name
 % clob # type
-% 130 # length
+% 88 # length
 union (
 | project (
 | | select (
-| | | table(sys.mt1) [ "mt1"."id" as "test"."id", "mt1"."posx" as 
"test"."posx", "mt1"."%TID%" NOT NULL as "test"."%TID%" ] COUNT 
+| | | table(sys.mt1) [ "mt1"."id" as "test"."id", "mt1"."posx" as 
"test"."posx" ] COUNT 
 | | ) [ bigint "1" <= "test"."id" <= bigint "10000" ]
 | ) [ "test"."id", "test"."posx" ],
 | project (
 | | select (
-| | | table(sys.mt2) [ "mt2"."id" as "test"."id", "mt2"."posx" as 
"test"."posx", "mt2"."%TID%" NOT NULL as "test"."%TID%" ] COUNT 
+| | | table(sys.mt2) [ "mt2"."id" as "test"."id", "mt2"."posx" as 
"test"."posx" ] COUNT 
 | | ) [ bigint "1" <= "test"."id" <= bigint "10000" ]
 | ) [ "test"."id", "test"."posx" ]
 ) [ "test"."id", "test"."posx" ]
@@ -73,10 +73,10 @@ union (
 % .plan # table_name
 % rel # name
 % clob # type
-% 81 # length
+% 56 # length
 project (
 | select (
-| | table(sys.mt2) [ "test"."id", "test"."posx", "test"."%TID%" NOT NULL ] 
COUNT 
+| | table(sys.mt2) [ "test"."id", "test"."posx" ] COUNT 
 | ) [ bigint "1" <= "test"."id" <= bigint "1000" ]
 ) [ "test"."id", "test"."posx" ]
 #declare l integer;
@@ -87,16 +87,16 @@ project (
 % .plan # table_name
 % rel # name
 % clob # type
-% 130 # length
+% 88 # length
 union (
 | project (
 | | select (
-| | | table(sys.mt1) [ "mt1"."id" as "test"."id", "mt1"."posx" as 
"test"."posx", "mt1"."%TID%" NOT NULL as "test"."%TID%" ] COUNT 
+| | | table(sys.mt1) [ "mt1"."id" as "test"."id", "mt1"."posx" as 
"test"."posx" ] COUNT 
 | | ) [ bigint[l] <= "test"."id" <= bigint[h] ]
 | ) [ "test"."id", "test"."posx" ],
 | project (
 | | select (
-| | | table(sys.mt2) [ "mt2"."id" as "test"."id", "mt2"."posx" as 
"test"."posx", "mt2"."%TID%" NOT NULL as "test"."%TID%" ] COUNT 
+| | | table(sys.mt2) [ "mt2"."id" as "test"."id", "mt2"."posx" as 
"test"."posx" ] COUNT 
 | | ) [ bigint[l] <= "test"."id" <= bigint[h] ]
 | ) [ "test"."id", "test"."posx" ]
 ) [ "test"."id", "test"."posx" ]
@@ -105,26 +105,26 @@ union (
 % .plan # table_name
 % rel # name
 % clob # type
-% 81 # length
+% 56 # length
 project (
 | select (
-| | table(sys.mt2) [ "test"."id", "test"."posx", "test"."%TID%" NOT NULL ] 
COUNT 
+| | table(sys.mt2) [ "test"."id", "test"."posx" ] COUNT 
 | ) [ bigint[l] <= "test"."id" <= bigint[h] ]
 ) [ "test"."id", "test"."posx" ]
 #plan select * from test where id between 1 and 1000*10;
 % .plan # table_name
 % rel # name
 % clob # type
-% 130 # length
+% 89 # length
 union (
 | project (
 | | select (
-| | | table(sys.mt1) [ "mt1"."id" as "test"."id", "mt1"."posx" as 
"test"."posx", "mt1"."%TID%" NOT NULL as "test"."%TID%" ] COUNT 
+| | | table(sys.mt1) [ "mt1"."id" as "test"."id", "mt1"."posx" as 
"test"."posx" ] COUNT 
 | | ) [ bigint "1" <= "test"."id" <= bigint[sys.sql_mul(smallint "1000", 
tinyint "10")] ]
 | ) [ "test"."id", "test"."posx" ],
 | project (
 | | select (
-| | | table(sys.mt2) [ "mt2"."id" as "test"."id", "mt2"."posx" as 
"test"."posx", "mt2"."%TID%" NOT NULL as "test"."%TID%" ] COUNT 
+| | | table(sys.mt2) [ "mt2"."id" as "test"."id", "mt2"."posx" as 
"test"."posx" ] COUNT 
 | | ) [ bigint "1" <= "test"."id" <= bigint[sys.sql_mul(smallint "1000", 
tinyint "10")] ]
 | ) [ "test"."id", "test"."posx" ]
 ) [ "test"."id", "test"."posx" ]
@@ -132,16 +132,16 @@ union (
 % .plan # table_name
 % rel # name
 % clob # type
-% 130 # length
+% 88 # length
 union (
 | project (
 | | select (
-| | | table(sys.mt1) [ "mt1"."id" as "test"."id", "mt1"."posx" as 
"test"."posx", "mt1"."%TID%" NOT NULL as "test"."%TID%" ] COUNT 
+| | | table(sys.mt1) [ "mt1"."id" as "test"."id", "mt1"."posx" as 
"test"."posx" ] COUNT 
 | | ) [ bigint "1" <= "test"."id" <= bigint[sys.sql_mul(smallint "100", 
tinyint "10")] ]
 | ) [ "test"."id", "test"."posx" ],
 | project (
 | | select (
-| | | table(sys.mt2) [ "mt2"."id" as "test"."id", "mt2"."posx" as 
"test"."posx", "mt2"."%TID%" NOT NULL as "test"."%TID%" ] COUNT 
+| | | table(sys.mt2) [ "mt2"."id" as "test"."id", "mt2"."posx" as 
"test"."posx" ] COUNT 
 | | ) [ bigint "1" <= "test"."id" <= bigint[sys.sql_mul(smallint "100", 
tinyint "10")] ]
 | ) [ "test"."id", "test"."posx" ]
 ) [ "test"."id", "test"."posx" ]
@@ -149,16 +149,16 @@ union (
 % .plan # table_name
 % rel # name
 % clob # type
-% 130 # length
+% 88 # length
 union (
 | project (
 | | select (
-| | | table(sys.mt1) [ "mt1"."id" as "test"."id", "mt1"."posx" as 
"test"."posx", "mt1"."%TID%" NOT NULL as "test"."%TID%" ] COUNT 
+| | | table(sys.mt1) [ "mt1"."id" as "test"."id", "mt1"."posx" as 
"test"."posx" ] COUNT 
 | | ) [ "test"."id" in (bigint "1", bigint "1022") ]
 | ) [ "test"."id", "test"."posx" ],
 | project (
 | | select (
-| | | table(sys.mt2) [ "mt2"."id" as "test"."id", "mt2"."posx" as 
"test"."posx", "mt2"."%TID%" NOT NULL as "test"."%TID%" ] COUNT 
+| | | table(sys.mt2) [ "mt2"."id" as "test"."id", "mt2"."posx" as 
"test"."posx" ] COUNT 
 | | ) [ "test"."id" in (bigint "1", bigint "1022") ]
 | ) [ "test"."id", "test"."posx" ]
 ) [ "test"."id", "test"."posx" ]
@@ -166,10 +166,10 @@ union (
 % .plan # table_name
 % rel # name
 % clob # type
-% 81 # length
+% 56 # length
 project (
 | select (
-| | table(sys.mt2) [ "test"."id", "test"."posx", "test"."%TID%" NOT NULL ] 
COUNT 
+| | table(sys.mt2) [ "test"."id", "test"."posx" ] COUNT 
 | ) [ "test"."id" in (bigint "1", bigint "1000") ]
 ) [ "test"."id", "test"."posx" ]
 #drop table test;
diff --git a/sql/test/remote/Tests/partition_elim.stable.out 
b/sql/test/remote/Tests/partition_elim.stable.out
--- a/sql/test/remote/Tests/partition_elim.stable.out
+++ b/sql/test/remote/Tests/partition_elim.stable.out
@@ -136,60 +136,60 @@ Ready.
 % clob # type
 % 117 # length
 function user.main():void;
-    X_5:void := querylog.define("explain select x,y from test where x between 
4.0 and 6.0;", "default_pipe", 49:int);
-barrier X_143 := language.dataflow();
-    X_40:bat[:dbl] := bat.new(nil:dbl);
+    X_5:void := querylog.define("explain select x,y from test where x between 
4.0 and 6.0;", "default_pipe", 47:int);
+barrier X_139 := language.dataflow();
+    X_38:bat[:dbl] := bat.new(nil:dbl);
     X_8 := sql.mvc();
-    X_119:bat[:dbl] := sql.bind(X_8, "sys", "test2", "x", 0:int, 0:int, 2:int);
-    C_116:bat[:oid] := sql.tid(X_8, "sys", "test2", 0:int, 2:int);
-    C_124 := algebra.select(X_119, C_116, 4:dbl, 6:dbl, true, true, false);
-    X_126 := algebra.projection(C_124, X_119);
-    X_120:bat[:dbl] := sql.bind(X_8, "sys", "test2", "x", 0:int, 1:int, 2:int);
-    C_118:bat[:oid] := sql.tid(X_8, "sys", "test2", 1:int, 2:int);
-    C_125 := algebra.select(X_120, C_118, 4:dbl, 6:dbl, true, true, false);
-    X_127 := algebra.projection(C_125, X_120);
-    X_138 := mat.packIncrement(X_126, 2:int);
-    X_25 := mat.packIncrement(X_138, X_127);
-    X_30:bat[:dbl] := sql.bind(X_8, "sys", "test3", "x", 0:int);
-    C_28:bat[:oid] := sql.tid(X_8, "sys", "test3");
-    C_36 := algebra.select(X_30, C_28, 4:dbl, 6:dbl, true, true, false);
-    X_32:bat[:dbl] := sql.bind(X_8, "sys", "test3", "y", 0:int);
-    X_38 := algebra.projection(C_36, X_32);
-    X_37 := algebra.projection(C_36, X_30);
-    X_122:bat[:dbl] := sql.bind(X_8, "sys", "test2", "y", 0:int, 1:int, 2:int);
-    X_129 := algebra.projection(C_125, X_122);
-    X_121:bat[:dbl] := sql.bind(X_8, "sys", "test2", "y", 0:int, 0:int, 2:int);
-    X_128 := algebra.projection(C_124, X_121);
-    X_42 := bat.append(X_40, X_25, true);
-    X_43 := bat.append(X_42, X_37, true);
-    X_44:bat[:dbl] := bat.new(nil:dbl);
-    X_140 := mat.packIncrement(X_128, 2:int);
-    X_26 := mat.packIncrement(X_140, X_129);
-    X_45 := bat.append(X_44, X_26, true);
-    X_46 := bat.append(X_45, X_38, true);
+    X_115:bat[:dbl] := sql.bind(X_8, "sys", "test2", "x", 0:int, 0:int, 2:int);
+    C_112:bat[:oid] := sql.tid(X_8, "sys", "test2", 0:int, 2:int);
+    C_120 := algebra.select(X_115, C_112, 4:dbl, 6:dbl, true, true, false);
+    X_122 := algebra.projection(C_120, X_115);
+    X_116:bat[:dbl] := sql.bind(X_8, "sys", "test2", "x", 0:int, 1:int, 2:int);
+    C_114:bat[:oid] := sql.tid(X_8, "sys", "test2", 1:int, 2:int);
+    C_121 := algebra.select(X_116, C_114, 4:dbl, 6:dbl, true, true, false);
+    X_123 := algebra.projection(C_121, X_116);
+    X_134 := mat.packIncrement(X_122, 2:int);
+    X_25 := mat.packIncrement(X_134, X_123);
+    X_29:bat[:dbl] := sql.bind(X_8, "sys", "test3", "x", 0:int);
+    C_27:bat[:oid] := sql.tid(X_8, "sys", "test3");
+    C_35 := algebra.select(X_29, C_27, 4:dbl, 6:dbl, true, true, false);
+    X_31:bat[:dbl] := sql.bind(X_8, "sys", "test3", "y", 0:int);
+    X_37 := algebra.projection(C_35, X_31);
+    X_36 := algebra.projection(C_35, X_29);
+    X_118:bat[:dbl] := sql.bind(X_8, "sys", "test2", "y", 0:int, 1:int, 2:int);
+    X_125 := algebra.projection(C_121, X_118);
+    X_117:bat[:dbl] := sql.bind(X_8, "sys", "test2", "y", 0:int, 0:int, 2:int);
+    X_124 := algebra.projection(C_120, X_117);
+    X_40 := bat.append(X_38, X_25, true);
+    X_41 := bat.append(X_40, X_36, true);
+    X_42:bat[:dbl] := bat.new(nil:dbl);
+    X_136 := mat.packIncrement(X_124, 2:int);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to