Changeset: 4b4f938bfcaa for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4b4f938bfcaa
Added Files:
        sql/test/merge-partitions/Tests/mergepart10.stable.err
        sql/test/merge-partitions/Tests/mergepart10.stable.out
Modified Files:
        sql/backends/monet5/rel_bin.c
        sql/server/rel_optimizer.c
        sql/server/rel_updates.c
        sql/test/merge-partitions/Tests/mergepart10.sql
Branch: merge-partitions
Log Message:

Distribute update queries when the partitioned column is not being updated 
(easy case)


diffs (truncated from 521 to 300 lines):

diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -4414,6 +4414,9 @@ rel2bin_update(backend *be, sql_rel *rel
                cnt = s;
        }
 
+       if(be->cur_append) //building the total number of rows affected across 
all tables
+               cnt->nr = add_to_merge_partitions_accumulator(be, cnt->nr);
+
        if (sql->cascade_action) 
                sql->cascade_action = NULL;
        return cnt;
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
@@ -8064,8 +8064,6 @@ exp_change_column_table(mvc *sql, sql_ex
                case e_column: {
                        if(!strcmp(e->l, oldt->base.name))
                                e->l = sa_strdup(sql->sa, newt->base.name);
-                       if(!strcmp(e->rname, oldt->base.name))
-                               e->rname = sa_strdup(sql->sa, newt->base.name);
                } break;
                case e_cmp: {
                        if (e->flag == cmp_in || e->flag == cmp_notin) {
@@ -8087,6 +8085,8 @@ exp_change_column_table(mvc *sql, sql_ex
                        }
                } break;
        }
+       if(e->rname && !strcmp(e->rname, oldt->base.name))
+               e->rname = sa_strdup(sql->sa, newt->base.name);
        return e;
 }
 
@@ -8363,21 +8363,33 @@ rel_merge_table_rewrite(int *changes, mv
                                        exception = exp_exception(sql->sa, 
aggr, buf);
                                        sel = rel_ddl_distribute(sql->sa, sel, 
anti_dup, list_append(new_exp_list(sql->sa), exception));
                                } else if(is_update(rel->op)) {
-                                       /*int colr = t->pcol->colnr;
+                                       /*int found_part_col = 0;
+
+                                       for (node *n = 
((sql_rel*)rel->r)->exps->h; n; n = n->next) {
+                                               sql_exp* exp = (sql_exp*) 
n->data;
+                                               if(exp->type == e_column) {
+                                                       sql_exp* l = (sql_exp*) 
exp->l;
+                                                       if(!strcmp((char*)l->l, 
t->base.name) && !strcmp((char*)l->r, t->pcol->base.name))
+                                                               found_part_col 
= 1;
+                                               }
+                                       }*/
 
                                        for (node *n = t->members.set->h; n; n 
= n->next) {
                                                sql_part *pt = (sql_part *) 
n->data;
                                                sql_table *sub = 
find_sql_table(t->s, pt->base.name);
                                                sql_rel *s1, *dup = NULL;
+                                               list *uexps = 
exps_copy(sql->sa, rel->exps);
 
                                                if(rel->r) {
                                                        dup = rel_copy(sql->sa, 
rel->r, 1);
                                                        dup = 
rel_change_base_table(sql, dup, t, sub);
                                                }
-                                               rel_update(sql, 
rel_basetable(sql, sub, sub->base.name), rel, sql_exp **updates, list_dup(dup, 
NULL));
-
-
-                                               s1 = 
rel_truncate_duplicate(sql->sa, rel_basetable(sql, sub, sub->base.name), rel);
+
+                                               for(node *ne = uexps->h ; ne ; 
ne = ne->next)
+                                                       ne->data = 
exp_change_column_table(sql, (sql_exp*) ne->data, t, sub);
+
+                                               //easy scenario where the 
partitioned column is not being updated
+                                               s1 = rel_update(sql, 
rel_basetable(sql, sub, sub->base.name), dup, NULL, uexps);
                                                if (just_one == 0) {
                                                        sel = rel_list(sql->sa, 
sel, s1);
                                                } else {
@@ -8386,8 +8398,7 @@ rel_merge_table_rewrite(int *changes, mv
                                                }
                                                (*changes)++;
                                        }
-                                       sel = rel_ddl_distribute(sql->sa, sel, 
NULL, NULL);*/
-
+                                       sel = rel_ddl_distribute(sql->sa, sel, 
NULL, NULL);
                                }
                        } else if(t->p && (isRangePartitionTable(t->p) || 
isListPartitionTable(t->p))
                                          && !find_prop(left->p, PROP_USED) && 
is_insert(rel->op)) {
diff --git a/sql/server/rel_updates.c b/sql/server/rel_updates.c
--- a/sql/server/rel_updates.c
+++ b/sql/server/rel_updates.c
@@ -832,7 +832,7 @@ rel_update(mvc *sql, sql_rel *t, sql_rel
        if(!r)
                return NULL;
 
-       if (tab)
+       if (tab && updates)
        for (m = tab->columns.set->h; m; m = m->next) {
                sql_column *c = m->data;
                sql_exp *v = updates[c->colnr];
diff --git a/sql/test/merge-partitions/Tests/mergepart10.sql 
b/sql/test/merge-partitions/Tests/mergepart10.sql
--- a/sql/test/merge-partitions/Tests/mergepart10.sql
+++ b/sql/test/merge-partitions/Tests/mergepart10.sql
@@ -7,7 +7,7 @@ DELETE FROM testsmallpartitions WHERE a 
 TRUNCATE testsmallpartitions; --error
 UPDATE testsmallpartitions SET b = 'try update me'; --error
 
-ALTER TABLE testsmallpartitions ADD TABLE testingme AS PARTITION IN ('100');
+ALTER TABLE testsmallpartitions ADD TABLE testingme AS PARTITION IN ('100', 
300, '400');
 
 DELETE FROM testsmallpartitions;
 DELETE FROM testsmallpartitions WHERE a < 400;
@@ -20,9 +20,54 @@ INSERT INTO testsmallpartitions VALUES (
 DELETE FROM testsmallpartitions WHERE a < 400;
 INSERT INTO testsmallpartitions VALUES (100, 'more'), (100, 'testing'), (100, 
'please'), (100, 'now');
 TRUNCATE testsmallpartitions;
-INSERT INTO testsmallpartitions VALUES (100, 'just'), (100, 'one'), (100, 
'more'), (100, 'insert');
-UPDATE testsmallpartitions SET b = 'updating';
+INSERT INTO testsmallpartitions VALUES (300, 'just'), (100, 'one'), (300, 
'more'), (100, 'insert');
+
+SELECT a, b FROM testsmallpartitions;
+SELECT a, b FROM testingme;
+
+UPDATE testsmallpartitions SET b = 'nothing' WHERE a = 0;
+UPDATE testsmallpartitions SET b = 'another update' WHERE a = 100;
+
+SELECT a, b FROM testsmallpartitions;
+SELECT a, b FROM testingme;
+
+UPDATE testsmallpartitions SET b = 'change' || 'me' WHERE a = 300;
+
+SELECT a, b FROM testsmallpartitions;
+SELECT a, b FROM testingme;
+
+CREATE TABLE testmealso (a int, b varchar(32));
+ALTER TABLE testsmallpartitions ADD TABLE testmealso AS PARTITION IN ('200', 
500);
+
+INSERT INTO testsmallpartitions VALUES (100, 'more'), (200, 'data'), (100, 
'to'), (400, 'test'), (500, 'on');
+
+UPDATE testsmallpartitions SET b = 'on both partitions' WHERE a = 400 OR a = 
200;
+
+SELECT a, b FROM testsmallpartitions;
+SELECT a, b FROM testingme;
+SELECT a, b FROM testmealso;
+
+UPDATE testsmallpartitions SET b = 'just on the second partition' WHERE a = 
500;
+
+SELECT a, b FROM testsmallpartitions;
+SELECT a, b FROM testingme;
+SELECT a, b FROM testmealso;
+
+UPDATE testsmallpartitions SET b = 'no partition' WHERE a = 1000;
+
+SELECT a, b FROM testsmallpartitions;
+SELECT a, b FROM testingme;
+SELECT a, b FROM testmealso;
+
+TRUNCATE testsmallpartitions;
+
+SELECT a, b FROM testsmallpartitions;
+SELECT a, b FROM testingme;
+SELECT a, b FROM testmealso;
 
 ALTER TABLE testsmallpartitions DROP TABLE testingme;
+ALTER TABLE testsmallpartitions DROP TABLE testmealso;
+
 DROP TABLE testingme;
+DROP TABLE testmealso;
 DROP TABLE testsmallpartitions;
diff --git a/sql/test/merge-partitions/Tests/mergepart10.stable.err 
b/sql/test/merge-partitions/Tests/mergepart10.stable.err
new file mode 100644
--- /dev/null
+++ b/sql/test/merge-partitions/Tests/mergepart10.stable.err
@@ -0,0 +1,57 @@
+stderr of test 'mergepart10` in directory 'sql/test/merge-partitions` itself:
+
+
+# 16:03:30 >  
+# 16:03:30 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=33102" "--set" 
"mapi_usock=/var/tmp/mtest-28164/.s.monetdb.33102" "--set" "monet_prompt=" 
"--forcemito" 
"--dbpath=/home/ferreira/repositories/MonetDB-merge-partitions/BUILD/var/MonetDB/mTests_sql_test_merge-partitions"
 "--set" "embedded_r=yes" "--set" "embedded_py=true" "--set" "embedded_c=true"
+# 16:03:30 >  
+
+# builtin opt  gdk_dbpath = 
/home/ferreira/repositories/MonetDB-merge-partitions/BUILD/var/monetdb5/dbfarm/demo
+# builtin opt  gdk_debug = 0
+# builtin opt  gdk_vmtrim = no
+# builtin opt  monet_prompt = >
+# builtin opt  monet_daemon = no
+# builtin opt  mapi_port = 50000
+# builtin opt  mapi_open = false
+# builtin opt  mapi_autosense = false
+# builtin opt  sql_optimizer = default_pipe
+# builtin opt  sql_debug = 0
+# cmdline opt  gdk_nr_threads = 0
+# cmdline opt  mapi_open = true
+# cmdline opt  mapi_port = 33102
+# cmdline opt  mapi_usock = /var/tmp/mtest-28164/.s.monetdb.33102
+# cmdline opt  monet_prompt = 
+# cmdline opt  gdk_dbpath = 
/home/ferreira/repositories/MonetDB-merge-partitions/BUILD/var/MonetDB/mTests_sql_test_merge-partitions
+# cmdline opt  embedded_r = yes
+# cmdline opt  embedded_py = true
+# cmdline opt  embedded_c = true
+# cmdline opt  gdk_debug = 553648138
+
+# 16:03:30 >  
+# 16:03:30 >  "mclient" "-lsql" "-ftest" "-tnone" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-28164" "--port=33102"
+# 16:03:30 >  
+
+MAPI  = (monetdb) /var/tmp/mtest-28164/.s.monetdb.33102
+QUERY = INSERT INTO testsmallpartitions VALUES (1, 'fail'); --error
+ERROR = !INSERT INTO: list partitioned table 'testsmallpartitions' has no 
partitions set
+CODE  = 42000
+MAPI  = (monetdb) /var/tmp/mtest-28164/.s.monetdb.33102
+QUERY = DELETE FROM testsmallpartitions; --error
+ERROR = !DELETE FROM: list partitioned table 'testsmallpartitions' has no 
partitions set
+CODE  = 42000
+MAPI  = (monetdb) /var/tmp/mtest-28164/.s.monetdb.33102
+QUERY = DELETE FROM testsmallpartitions WHERE a < 400; --error
+ERROR = !DELETE FROM: list partitioned table 'testsmallpartitions' has no 
partitions set
+CODE  = 42000
+MAPI  = (monetdb) /var/tmp/mtest-28164/.s.monetdb.33102
+QUERY = TRUNCATE testsmallpartitions; --error
+ERROR = !TRUNCATE: list partitioned table 'testsmallpartitions' has no 
partitions set
+CODE  = 42000
+MAPI  = (monetdb) /var/tmp/mtest-28164/.s.monetdb.33102
+QUERY = UPDATE testsmallpartitions SET b = 'try update me'; --error
+ERROR = !UPDATE: list partitioned table 'testsmallpartitions' has no 
partitions set
+CODE  = 42000
+
+# 16:03:31 >  
+# 16:03:31 >  "Done."
+# 16:03:31 >  
+
diff --git a/sql/test/merge-partitions/Tests/mergepart10.stable.out 
b/sql/test/merge-partitions/Tests/mergepart10.stable.out
new file mode 100644
--- /dev/null
+++ b/sql/test/merge-partitions/Tests/mergepart10.stable.out
@@ -0,0 +1,290 @@
+stdout of test 'mergepart10` in directory 'sql/test/merge-partitions` itself:
+
+
+# 16:03:30 >  
+# 16:03:30 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=33102" "--set" 
"mapi_usock=/var/tmp/mtest-28164/.s.monetdb.33102" "--set" "monet_prompt=" 
"--forcemito" 
"--dbpath=/home/ferreira/repositories/MonetDB-merge-partitions/BUILD/var/MonetDB/mTests_sql_test_merge-partitions"
 "--set" "embedded_r=yes" "--set" "embedded_py=true" "--set" "embedded_c=true"
+# 16:03:30 >  
+
+# MonetDB 5 server v11.30.0
+# This is an unreleased version
+# Serving database 'mTests_sql_test_merge-partitions', using 8 threads
+# Compiled for x86_64-pc-linux-gnu/64bit with 128bit integers
+# Found 15.492 GiB available main-memory.
+# Copyright (c) 1993 - July 2008 CWI.
+# Copyright (c) August 2008 - 2018 MonetDB B.V., all rights reserved
+# Visit https://www.monetdb.org/ for further information
+# Listening for connection requests on 
mapi:monetdb://dhcp-23.eduroam.cwi.nl:33102/
+# Listening for UNIX domain connection requests on 
mapi:monetdb:///var/tmp/mtest-28164/.s.monetdb.33102
+# MonetDB/GIS module loaded
+# MonetDB/SQL module loaded
+# MonetDB/Python2 module loaded
+# MonetDB/R   module loaded
+
+Ready.
+# SQL catalog created, loading sql scripts once
+# loading sql script: 09_like.sql
+# loading sql script: 10_math.sql
+# loading sql script: 11_times.sql
+# loading sql script: 12_url.sql
+# loading sql script: 13_date.sql
+# loading sql script: 14_inet.sql
+# loading sql script: 15_querylog.sql
+# loading sql script: 16_tracelog.sql
+# loading sql script: 17_temporal.sql
+# loading sql script: 18_index.sql
+# loading sql script: 20_vacuum.sql
+# loading sql script: 21_dependency_functions.sql
+# loading sql script: 21_dependency_views.sql
+# loading sql script: 22_clients.sql
+# loading sql script: 23_skyserver.sql
+# loading sql script: 25_debug.sql
+# loading sql script: 26_sysmon.sql
+# loading sql script: 27_rejects.sql
+# loading sql script: 39_analytics.sql
+# loading sql script: 39_analytics_hge.sql
+# loading sql script: 40_geom.sql
+# loading sql script: 40_json.sql
+# loading sql script: 40_json_hge.sql
+# loading sql script: 41_md5sum.sql
+# loading sql script: 45_uuid.sql
+# loading sql script: 46_profiler.sql
+# loading sql script: 51_sys_schema_extension.sql
+# loading sql script: 60_wlcr.sql
+# loading sql script: 72_fits.sql
+# loading sql script: 74_netcdf.sql
+# loading sql script: 75_lidar.sql
+# loading sql script: 75_shp.sql
+# loading sql script: 75_storagemodel.sql
+# loading sql script: 80_statistics.sql
+# loading sql script: 80_udf.sql
+# loading sql script: 80_udf_hge.sql
+# loading sql script: 85_bam.sql
+# loading sql script: 90_generator.sql
+# loading sql script: 90_generator_hge.sql
+# loading sql script: 99_system.sql
+
+# 16:03:30 >  
+# 16:03:30 >  "mclient" "-lsql" "-ftest" "-tnone" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-28164" "--port=33102"
+# 16:03:30 >  
+
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to