Changeset: 4ef264fbed9c for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4ef264fbed9c
Modified Files:
sql/server/rel_optimizer.c
sql/test/BugDay_2005-10-06_2.9.3/Tests/BATpropcheck_error.SF-1012739.stable.out
sql/test/BugDay_2005-10-06_2.9.3/Tests/CrashMe_SQL_server_crash-2.SF-921673.stable.out
sql/test/BugDay_2005-10-06_2.9.3/Tests/create_view_with_check_options.SF-1314951.stable.out
sql/test/BugDay_2005-10-06_2.9.3/Tests/jdbc_crashes_on_getTables.SF_944316.stable.out
sql/test/BugDay_2005-10-06_2.9.3/Tests/view_on_deleted_table.SF-938583.stable.out
sql/test/BugDay_2005-11-09_2.8/Tests/ORDER_BY_evaluation_error.SF-1023658.stable.out
sql/test/BugDay_2005-11-09_2.9.3/Tests/alias_union_join.SF-1063089.stable.out
sql/test/BugDay_2005-11-09_2.9.3/Tests/schema_change.SF-1026845.stable.out
sql/test/BugTracker-2008/Tests/view_reply_incorrect.SF-2075097.stable.out
sql/test/BugTracker-2009/Tests/cardinality_of_expression_is_wrong.SF-2581617.stable.out
sql/test/BugTracker-2009/Tests/lookup_column_name_bug_1.SF-2654300.stable.out
sql/test/BugTracker-2009/Tests/lookup_column_name_bug_2.SF-2656762.stable.out
sql/test/BugTracker-2009/Tests/push_select_down_crash.stable.out
sql/test/BugTracker-2010/Tests/select-view-key.Bug-2673.stable.out
sql/test/BugTracker-2011/Tests/merge_range_exp.Bug-2806.stable.out
sql/test/BugTracker-2011/Tests/nested_select.Bug-2801.stable.out
sql/test/BugTracker/Tests/nested_views_algebra_version.SF-1993765.stable.out
sql/test/BugTracker/Tests/variable_stack_crash.SF-1711251-2.stable.out
sql/test/BugTracker/Tests/variable_stack_crash.SF-1711251.stable.out
sql/test/Tests/create_in_schema.stable.out
sql/test/bugs/Tests/case_cast-bug-sf-1019506.stable.out
sql/test/bugs/Tests/groupby_having-bug-sf-947600.stable.out
sql/test/bugs/Tests/select_orderby_alias-bug-sf-1024615.stable.out
sql/test/mserver5-sql-readonly/Tests/mserver5-sql-readonly-view.stable.out
sql/test/osm/Tests/exp_name_bug.stable.out
sql/test/xquery/Tests/q01.stable.out
Branch: default
Log Message:
push join down union part 2. Also split joins with simple union-all's (ie
without
joinidx)
diffs (truncated from 736 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
@@ -1107,12 +1107,14 @@
list *nl = new_exp_list(sql->sa);
for(n = exps->h; n; n = n->next) {
- sql_exp *arg = n->data;
-
- arg = _exp_push_down(sql, arg, f, t);
- if (!arg)
+ sql_exp *arg = n->data, *narg = NULL;
+
+ narg = _exp_push_down(sql, arg, f, t);
+ if (!narg)
return NULL;
- append(nl, arg);
+ if (arg->p)
+ narg->p = prop_copy(sql->sa, arg->p);
+ append(nl, narg);
}
return nl;
}
@@ -1445,6 +1447,10 @@
tname = ne->rname;
ne->rname = NULL; /* prevent
from being freed prematurely in exp_setname */
}
+ /* use previous table in case its not
set */
+ if (!tname && e->l && ne->l &&
+ strcmp(e->l, ne->l) != 0)
+ tname = e->l;
exp_setname(sql->sa, ne, tname,
e->name);
list_append(rel->exps, ne);
} else {
@@ -2485,6 +2491,20 @@
*
* TODO: There are possibly projections around the unions !
*/
+static void
+rel_rename_exps( mvc *sql, list *exps1, list *exps2)
+{
+ node *n, *m;
+
+ assert(list_length(exps1) == list_length(exps2));
+ for (n = exps1->h, m = exps2->h; n && m; n = n->next, m = m->next) {
+ sql_exp *e1 = n->data;
+ sql_exp *e2 = m->data;
+
+ exp_setname(sql->sa, e2, e1->rname, e1->name );
+ }
+}
+
static sql_rel *
rel_push_join_down_union(int *changes, mvc *sql, sql_rel *rel)
{
@@ -2495,22 +2515,35 @@
list *exps = rel->exps;
sql_exp *je = exps->h->data;
- if (!find_prop(je->p, PROP_JOINIDX))
- return rel;
if (l->op == op_project)
l = l->l;
if (r->op == op_project)
r = r->l;
- if (l->op == op_union && r->op != op_union) {
+
+ /* both sides only if we have a join index */
+ if (!l || !r ||(l->op == op_union && r->op == op_union &&
+ !find_prop(je->p, PROP_JOINIDX)))
+ return rel;
+
+ ol->subquery = or->subquery = 0;
+ if ((l->op == op_union && !need_distinct(l)) && r->op !=
op_union) {
sql_rel *nl, *nr, *u;
sql_rel *ll = rel_dup(l->l), *lr = rel_dup(l->r);
/* join(union(a,b), c) -> union(join(a,c), join(b,c)) */
+ if (!is_project(ll->op))
+ ll = rel_project(sql->sa, ll,
+ rel_projections(sql, ll, NULL, 1, 1));
+ if (!is_project(lr->op))
+ lr = rel_project(sql->sa, lr,
+ rel_projections(sql, lr, NULL, 1, 1));
+ rel_rename_exps(sql, l->exps, ll->exps);
+ rel_rename_exps(sql, l->exps, lr->exps);
if (l != ol) {
ll = rel_project(sql->sa, ll, NULL);
- ll->exps = rel_projections(sql, ol, NULL, 1, 1);
+ ll->exps = exps_copy(sql->sa, ol->exps);
lr = rel_project(sql->sa, lr, NULL);
- lr->exps = rel_projections(sql, ol, NULL, 1, 1);
+ lr->exps = exps_copy(sql->sa, ol->exps);
}
nl = rel_crossproduct(sql->sa, ll, rel_dup(or),
rel->op);
nr = rel_crossproduct(sql->sa, lr, rel_dup(or),
rel->op);
@@ -2522,23 +2555,40 @@
rel_destroy(rel);
*changes = 1;
return u;
- } else if (l->op == op_union && r->op == op_union) {
+ } else if (l->op == op_union && !need_distinct(l) &&
+ r->op == op_union && !need_distinct(r)) {
sql_rel *nl, *nr, *u;
sql_rel *ll = rel_dup(l->l), *lr = rel_dup(l->r);
sql_rel *rl = rel_dup(r->l), *rr = rel_dup(r->r);
/* join(union(a,b), union(c,d)) -> union(join(a,c),
join(b,d)) */
+ if (!is_project(ll->op))
+ ll = rel_project(sql->sa, ll,
+ rel_projections(sql, ll, NULL, 1, 1));
+ if (!is_project(lr->op))
+ lr = rel_project(sql->sa, lr,
+ rel_projections(sql, lr, NULL, 1, 1));
+ rel_rename_exps(sql, l->exps, ll->exps);
+ rel_rename_exps(sql, l->exps, lr->exps);
if (l != ol) {
ll = rel_project(sql->sa, ll, NULL);
- ll->exps = rel_projections(sql, ol, NULL, 1, 1);
+ ll->exps = exps_copy(sql->sa, ol->exps);
lr = rel_project(sql->sa, lr, NULL);
- lr->exps = rel_projections(sql, ol, NULL, 1, 1);
+ lr->exps = exps_copy(sql->sa, ol->exps);
}
+ if (!is_project(rl->op))
+ rl = rel_project(sql->sa, rl,
+ rel_projections(sql, rl, NULL, 1, 1));
+ if (!is_project(rr->op))
+ rr = rel_project(sql->sa, rr,
+ rel_projections(sql, rr, NULL, 1, 1));
+ rel_rename_exps(sql, r->exps, rl->exps);
+ rel_rename_exps(sql, r->exps, rr->exps);
if (r != or) {
rl = rel_project(sql->sa, rl, NULL);
- rl->exps = rel_projections(sql, or, NULL, 1, 1);
+ rl->exps = exps_copy(sql->sa, or->exps);
rr = rel_project(sql->sa, rr, NULL);
- rr->exps = rel_projections(sql, or, NULL, 1, 1);
+ rr->exps = exps_copy(sql->sa, or->exps);
}
nl = rel_crossproduct(sql->sa, ll, rl, rel->op);
nr = rel_crossproduct(sql->sa, lr, rr, rel->op);
@@ -2550,16 +2600,25 @@
rel_destroy(rel);
*changes = 1;
return u;
- } else if (l->op != op_union && r->op == op_union) {
+ } else if (l->op != op_union &&
+ r->op == op_union && !need_distinct(r)) {
sql_rel *nl, *nr, *u;
sql_rel *rl = rel_dup(r->l), *rr = rel_dup(r->r);
/* join(a, union(b,c)) -> union(join(a,b), join(a,c)) */
+ if (!is_project(rl->op))
+ rl = rel_project(sql->sa, rl,
+ rel_projections(sql, rl, NULL, 1, 1));
+ if (!is_project(rr->op))
+ rr = rel_project(sql->sa, rr,
+ rel_projections(sql, rr, NULL, 1, 1));
+ rel_rename_exps(sql, r->exps, rl->exps);
+ rel_rename_exps(sql, r->exps, rr->exps);
if (r != or) {
rl = rel_project(sql->sa, rl, NULL);
- rl->exps = rel_projections(sql, or, NULL, 1, 1);
+ rl->exps = exps_copy(sql->sa, or->exps);
rr = rel_project(sql->sa, rr, NULL);
- rr->exps = rel_projections(sql, or, NULL, 1, 1);
+ rr->exps = exps_copy(sql->sa, or->exps);
}
nl = rel_crossproduct(sql->sa, rel_dup(ol), rl,
rel->op);
nr = rel_crossproduct(sql->sa, rel_dup(ol), rr,
rel->op);
@@ -3284,6 +3343,7 @@
if (rel->l && rel->exps) {
node *n;
list *exps = new_exp_list(sql->sa);
+
for(n=rel->exps->h; n; n = n->next) {
sql_exp *e = n->data;
diff --git
a/sql/test/BugDay_2005-10-06_2.9.3/Tests/BATpropcheck_error.SF-1012739.stable.out
b/sql/test/BugDay_2005-10-06_2.9.3/Tests/BATpropcheck_error.SF-1012739.stable.out
---
a/sql/test/BugDay_2005-10-06_2.9.3/Tests/BATpropcheck_error.SF-1012739.stable.out
+++
b/sql/test/BugDay_2005-10-06_2.9.3/Tests/BATpropcheck_error.SF-1012739.stable.out
@@ -46,7 +46,7 @@
#AND
# "tables"."name" LIKE 'voyages'
#ORDER BY "COLUMN_N
-% ., sys.schemas, .tables, sys.objects, sys.keys,
sys.keys # table_name
+% ., .schemas, .tables, .objects, .keys, .keys #
table_name
% TABLE_CAT, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, KEY_SEQ,
PK_NAME # name
% char, varchar, varchar, varchar, int, varchar
# type
% 0, 0, 0, 0, 1, 0 # length
diff --git
a/sql/test/BugDay_2005-10-06_2.9.3/Tests/CrashMe_SQL_server_crash-2.SF-921673.stable.out
b/sql/test/BugDay_2005-10-06_2.9.3/Tests/CrashMe_SQL_server_crash-2.SF-921673.stable.out
---
a/sql/test/BugDay_2005-10-06_2.9.3/Tests/CrashMe_SQL_server_crash-2.SF-921673.stable.out
+++
b/sql/test/BugDay_2005-10-06_2.9.3/Tests/CrashMe_SQL_server_crash-2.SF-921673.stable.out
@@ -21,11 +21,30 @@
Over..
-# 11:50:20 >
-# 11:50:20 > Mtimeout -timeout 60 MapiClient -lsql -umonetdb -Pmonetdb
--host=localhost --port=35781 < CrashMe_SQL_server_crash-2.SF-921673.sql
-# 11:50:20 >
+# 20:44:44 >
+# 20:44:44 > mclient -lsql -ftest -i -e --host=alf --port=36753
+# 20:44:44 >
-% ., sys.schemas, .tables, .columns, .columns,
.columns, .columns, ., ., ., ., .columns,
., ., ., ., ., ., . # table_name
+#SELECT null AS TABLE_CAT,
+# schemas.name AS TABLE_SCHEM,
+# tables.name AS TABLE_NAME,
+# columns.name AS COLUMN_NAME,
+# columns.type AS TYPE_NAME,
+# columns.type_digits AS COLUMN_SIZE,
+# columns.type_scale AS DECIMAL_DIGITS,
+# 0 AS BUFFER_LENGTH,
+# 10 AS NUM_PREC_RADIX,
+# null AS nullable,
+# null AS REMARKS,
+# columns."default" AS COLUMN_DEF,
+# 0 AS SQL_DATA_TYPE,
+# 0 AS SQL_DATETIME_SUB,
+# 0 AS CHAR_OCTET_LENGTH,
+# columns.number + 1 AS ORDINAL_POSITION,
+# null AS SCOPE_CATALOG,
+# null AS SCOPE_SCHEMA,
+# null AS SCOPE_TABLE
+% ., .schemas, .tables, .columns, .columns,
.columns, .columns, ., ., ., ., .columns,
., ., ., ., ., ., . # table_name
% table_cat, table_schem, table_name, column_name, type_name,
column_size, decimal_digits, buffer_length, num_prec_radix, nullable,
remarks, column_def, sql_data_type, sql_datetime_sub,
char_octet_length, ordinal_position, scope_catalog, scope_schema,
scope_table # name
% char, varchar, varchar, varchar, varchar,
int, int, tinyint, tinyint, char, char, varchar,
tinyint, tinyint, tinyint, int, char, char, char #
type
% 0, 3, 9, 12, 7, 4, 1, 1, 2, 0,
0, 0, 1, 1, 1, 2, 0, 0, 0 # length
diff --git
a/sql/test/BugDay_2005-10-06_2.9.3/Tests/create_view_with_check_options.SF-1314951.stable.out
b/sql/test/BugDay_2005-10-06_2.9.3/Tests/create_view_with_check_options.SF-1314951.stable.out
---
a/sql/test/BugDay_2005-10-06_2.9.3/Tests/create_view_with_check_options.SF-1314951.stable.out
+++
b/sql/test/BugDay_2005-10-06_2.9.3/Tests/create_view_with_check_options.SF-1314951.stable.out
@@ -22,7 +22,7 @@
[ 4 ]
#create view m as select * from t1314951 with check option;
#select * from m;
-% sys.t1314951 # table_name
+% sys.m # table_name
% v # name
% int # type
% 1 # length
diff --git
a/sql/test/BugDay_2005-10-06_2.9.3/Tests/jdbc_crashes_on_getTables.SF_944316.stable.out
b/sql/test/BugDay_2005-10-06_2.9.3/Tests/jdbc_crashes_on_getTables.SF_944316.stable.out
---
a/sql/test/BugDay_2005-10-06_2.9.3/Tests/jdbc_crashes_on_getTables.SF_944316.stable.out
+++
b/sql/test/BugDay_2005-10-06_2.9.3/Tests/jdbc_crashes_on_getTables.SF_944316.stable.out
@@ -21,11 +21,28 @@
Over..
-# 11:50:18 >
-# 11:50:18 > Mtimeout -timeout 60 MapiClient -lsql -umonetdb -Pmonetdb
--host=localhost --port=35781 < jdbc_crashes_on_getTables.SF_944316.sql
-# 11:50:18 >
+# 20:44:42 >
+# 20:44:42 > mclient -lsql -ftest -i -e --host=alf --port=36753
+# 20:44:42 >
-% .tables, sys.tables, .tables, .tables, .tables,
.tables, .tables, .tables, .tables, .tables #
table_name
+#SELECT * FROM (
+# SELECT
+# null AS "TABLE_CAT",
+# "schemas"."name" AS "TABLE_SCHEM",
+# "tables"."name" AS "TABLE_NAME",
+# 'SYSTEM TABLE' AS "TABLE_TYPE",
+# '' AS "REMARKS", null AS "TYPE_CAT",
+# null AS "TYPE_SCHEM",
+# null AS "TYPE_NAME",
+# 'id' AS "SELF_REFERENCING_COL_NAME",
+# 'SYSTEM' AS "REF_GENERATION"
+# FROM "tables", "schemas"
+# WHERE "tables"."schema_id" = "schemas"."id" AND "tables"."type" = 0
+#)
+#AS "tables"
+#WHERE 1 = 1 AND ("TABLE_TYPE" LIKE 'TABLE' OR "TABLE_TYPE" LIKE 'VIEW')
+#ORDER BY "TABLE_TYPE",
+% .tables, .tables, .tables, .tables, .tables,
.tables, .tables, .tables, .tables, .tables #
table_name
% TABLE_CAT, TABLE_SCHEM, TABLE_NAME, TABLE_TYPE, REMARKS,
TYPE_CAT, TYPE_SCHEM, TYPE_NAME, SELF_REFERENCING_COL_NAME,
REF_GENERATION # name
% char, varchar, varchar, char, char, char, char,
char, char, char # type
% 0, 0, 0, 12, 0, 0, 0, 0, 2, 6 #
length
diff --git
a/sql/test/BugDay_2005-10-06_2.9.3/Tests/view_on_deleted_table.SF-938583.stable.out
b/sql/test/BugDay_2005-10-06_2.9.3/Tests/view_on_deleted_table.SF-938583.stable.out
---
a/sql/test/BugDay_2005-10-06_2.9.3/Tests/view_on_deleted_table.SF-938583.stable.out
+++
b/sql/test/BugDay_2005-10-06_2.9.3/Tests/view_on_deleted_table.SF-938583.stable.out
@@ -24,7 +24,7 @@
#create table t_vdt (i int);
#create view v_vdt as select * from t_vdt;
#select * from v_vdt;
-% sys.t_vdt # table_name
+% sys.v_vdt # table_name
% i # name
% int # type
% 1 # length
diff --git
a/sql/test/BugDay_2005-11-09_2.8/Tests/ORDER_BY_evaluation_error.SF-1023658.stable.out
b/sql/test/BugDay_2005-11-09_2.8/Tests/ORDER_BY_evaluation_error.SF-1023658.stable.out
---
a/sql/test/BugDay_2005-11-09_2.8/Tests/ORDER_BY_evaluation_error.SF-1023658.stable.out
+++
b/sql/test/BugDay_2005-11-09_2.8/Tests/ORDER_BY_evaluation_error.SF-1023658.stable.out
@@ -32,7 +32,7 @@
# AND "tables"."schema_id" = "schemas"."id"
# AND "tables"."system" = FALSE
# AND "keys"."type" = 0;
-% sys.keys, sys.keys, sys.keys, sys.keys, sys.keys,
sys.keys, sys.objects, sys.objects, sys.objects, .tables,
.tables, .tables, .tables, .tables, .tables,
.tables, .tables, .tables, sys.schemas, sys.schemas,
sys.schemas, sys.schemas # table_name
+% .keys, .keys, .keys, .keys, .keys, .keys, .objects,
.objects, .objects, .tables, .tables, .tables,
.tables, .tables, .tables, .tables, .tables,
.tables, .schemas, .schemas, .schemas, .schemas #
table_name
% id, table_id, type, name, rkey, action, id, name, nr,
id, name, schema_id, query, type, system, commit_action,
readonly, temporary, id, name, authorization, owner # name
% int, int, int, varchar, int, int, int, varchar,
int, int, varchar, int, varchar, smallint,
boolean, smallint, boolean, tinyint, int,
varchar, int, int # type
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list