Changeset: 2255b42087dd for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2255b42087dd
Added Files:
        sql/test/BugTracker-2013/Tests/swapped_likejoin.Bug-3375.sql
        sql/test/BugTracker-2013/Tests/swapped_likejoin.Bug-3375.stable.err
        sql/test/BugTracker-2013/Tests/swapped_likejoin.Bug-3375.stable.out
Modified Files:
        sql/backends/monet5/LSST/Tests/lsst_htmxmatch.stable.out
        sql/backends/monet5/rel_bin.c
        sql/backends/monet5/sql_gencode.c
        sql/backends/monet5/sql_statement.c
        sql/backends/monet5/sql_statement.h
        sql/test/BugTracker-2013/Tests/All
Branch: Feb2013
Log Message:

fixed bug 3375. Handle swapping of join operants (in case of filter joins).


diffs (222 lines):

diff --git a/sql/backends/monet5/LSST/Tests/lsst_htmxmatch.stable.out 
b/sql/backends/monet5/LSST/Tests/lsst_htmxmatch.stable.out
--- a/sql/backends/monet5/LSST/Tests/lsst_htmxmatch.stable.out
+++ b/sql/backends/monet5/LSST/Tests/lsst_htmxmatch.stable.out
@@ -46,9 +46,9 @@ Ready.
 % bigint,      bigint # type
 % 3,   3 # length
 [ 100, 100     ]
-[ 101, 100     ]
-[ 102, 100     ]
-[ 103, 100     ]
+[ 100, 101     ]
+[ 100, 102     ]
+[ 100, 103     ]
 #drop table htm;
 
 # 21:23:59 >  
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
@@ -724,7 +724,7 @@ exp_bin(mvc *sql, sql_exp *e, stmt *left
                         if (left && right && re->card > CARD_ATOM && 
!is_select) {
                                /* find predicate function */
                                 sql_subfunc *f = e->f;
-                               stmt *j = stmt_joinN(sql->sa, l, r, r2, f);
+                               stmt *j = stmt_joinN(sql->sa, l, r, r2, f, 
swapped);
 
                                 if (j && is_anti(e))
                                         j->flag |= ANTI;
diff --git a/sql/backends/monet5/sql_gencode.c 
b/sql/backends/monet5/sql_gencode.c
--- a/sql/backends/monet5/sql_gencode.c
+++ b/sql/backends/monet5/sql_gencode.c
@@ -634,6 +634,7 @@ dump_joinN(backend *sql, MalBlkPtr mb, s
        char *mod, *fimp, *nme; 
        InstrPtr q;
        int op1, op2, op3 = 0;
+       bit swapped = (s->flag&SWAPPED)?TRUE:FALSE;
 
        if (backend_create_func(sql, s->op4.funcval->func) < 0)
                return -1;
@@ -655,10 +656,32 @@ dump_joinN(backend *sql, MalBlkPtr mb, s
                q = pushArgument(mb, q, op3);
        s->nr = getDestVar(q);
 
-       /* rename second result */
-       nme = GDKmalloc(SMALLBUFSIZ);
-       snprintf(nme, SMALLBUFSIZ, "r1_%d", s->nr);
-       renameVariable(mb, getArg(q,1), nme);
+       if (swapped) {
+               InstrPtr r = newInstruction(mb, ASSIGNsymbol);
+               getArg(r,0) = newTmpVariable(mb, TYPE_any);
+               getArg(r,1) = getArg(q,1);
+               r->retc = 1;
+               r->argc = 2;
+               pushInstruction(mb, r);
+               s->nr = getArg(r,0);
+
+               r = newInstruction(mb, ASSIGNsymbol);
+               getArg(r,0) = newTmpVariable(mb, TYPE_any);
+               getArg(r,1) = getArg(q,0);
+               r->retc = 1;
+               r->argc = 2;
+               pushInstruction(mb, r);
+
+               /* rename second result */
+               nme = GDKmalloc(SMALLBUFSIZ);
+               snprintf(nme, SMALLBUFSIZ, "r1_%d", s->nr);
+               renameVariable(mb, getArg(r,0), nme);
+       } else {
+               /* rename second result */
+               nme = GDKmalloc(SMALLBUFSIZ);
+               snprintf(nme, SMALLBUFSIZ, "r1_%d", s->nr);
+               renameVariable(mb, getArg(q,1), nme);
+       }
        return s->nr;
 }
 
diff --git a/sql/backends/monet5/sql_statement.c 
b/sql/backends/monet5/sql_statement.c
--- a/sql/backends/monet5/sql_statement.c
+++ b/sql/backends/monet5/sql_statement.c
@@ -1048,7 +1048,7 @@ stmt_join2(sql_allocator *sa, stmt *l, s
 }
 
 stmt *
-stmt_joinN(sql_allocator *sa, stmt *l, stmt *r, stmt *opt, sql_subfunc *op)
+stmt_joinN(sql_allocator *sa, stmt *l, stmt *r, stmt *opt, sql_subfunc *op, 
int swapped)
 {
        stmt *s = stmt_create(sa, st_joinN);
 
@@ -1057,6 +1057,8 @@ stmt_joinN(sql_allocator *sa, stmt *l, s
        s->op3 = opt;
        s->op4.funcval = op;
        s->nrcols = (opt)?3:2;
+       if (swapped)
+               s->flag |= SWAPPED;
        return s;
 }
 
diff --git a/sql/backends/monet5/sql_statement.h 
b/sql/backends/monet5/sql_statement.h
--- a/sql/backends/monet5/sql_statement.h
+++ b/sql/backends/monet5/sql_statement.h
@@ -210,7 +210,7 @@ extern stmt *stmt_tinter(sql_allocator *
 extern stmt *stmt_join(sql_allocator *sa, stmt *op1, stmt *op2, comp_type 
cmptype);
 extern stmt *stmt_join2(sql_allocator *sa, stmt *l, stmt *ra, stmt *rb, int 
cmp, int swapped);
 /* generic join operator, with a left and right statement list */
-extern stmt *stmt_joinN(sql_allocator *sa, stmt *l, stmt *r, stmt *opt, 
sql_subfunc *op);
+extern stmt *stmt_joinN(sql_allocator *sa, stmt *l, stmt *r, stmt *opt, 
sql_subfunc *op, int swapped);
 
 extern stmt *stmt_project(sql_allocator *sa, stmt *op1, stmt *op2);
 extern stmt *stmt_project_delta(sql_allocator *sa, stmt *col, stmt *upd, stmt 
*ins);
diff --git a/sql/test/BugTracker-2013/Tests/All 
b/sql/test/BugTracker-2013/Tests/All
--- a/sql/test/BugTracker-2013/Tests/All
+++ b/sql/test/BugTracker-2013/Tests/All
@@ -47,3 +47,4 @@ check-constraint.Bug-3335
 crash_after_creation_of_unique_key.Bug-3363
 alter_resets_readonly.Bug-3362
 env_errors.Bug-3370
+swapped_likejoin.Bug-3375
diff --git a/sql/test/BugTracker-2013/Tests/swapped_likejoin.Bug-3375.sql 
b/sql/test/BugTracker-2013/Tests/swapped_likejoin.Bug-3375.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2013/Tests/swapped_likejoin.Bug-3375.sql
@@ -0,0 +1,5 @@
+
+create table x (s string);
+insert into x values('%able%');
+select * from sys._tables, x where name like s;
+drop table x;
diff --git 
a/sql/test/BugTracker-2013/Tests/swapped_likejoin.Bug-3375.stable.err 
b/sql/test/BugTracker-2013/Tests/swapped_likejoin.Bug-3375.stable.err
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2013/Tests/swapped_likejoin.Bug-3375.stable.err
@@ -0,0 +1,35 @@
+stderr of test 'swapped_likejoin.Bug-3375` in directory 
'sql/test/BugTracker-2013` itself:
+
+
+# 10:06:32 >  
+# 10:06:32 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=34205" "--set" 
"mapi_usock=/var/tmp/mtest-22741/.s.monetdb.34205" "--set" "monet_prompt=" 
"--forcemito" "--set" "mal_listing=2" 
"--dbpath=/home/niels/scratch/rc-clean/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2013"
 "--set" "mal_listing=0"
+# 10:06:32 >  
+
+# builtin opt  gdk_dbpath = 
/home/niels/scratch/rc-clean/Linux-x86_64/var/monetdb5/dbfarm/demo
+# builtin opt  gdk_debug = 0
+# builtin opt  gdk_vmtrim = yes
+# 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 = 34205
+# cmdline opt  mapi_usock = /var/tmp/mtest-22741/.s.monetdb.34205
+# cmdline opt  monet_prompt = 
+# cmdline opt  mal_listing = 2
+# cmdline opt  gdk_dbpath = 
/home/niels/scratch/rc-clean/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2013
+# cmdline opt  mal_listing = 0
+
+# 10:06:32 >  
+# 10:06:32 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-22741" "--port=34205"
+# 10:06:32 >  
+
+
+# 10:06:32 >  
+# 10:06:32 >  "Done."
+# 10:06:32 >  
+
diff --git 
a/sql/test/BugTracker-2013/Tests/swapped_likejoin.Bug-3375.stable.out 
b/sql/test/BugTracker-2013/Tests/swapped_likejoin.Bug-3375.stable.out
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2013/Tests/swapped_likejoin.Bug-3375.stable.out
@@ -0,0 +1,50 @@
+stdout of test 'swapped_likejoin.Bug-3375` in directory 
'sql/test/BugTracker-2013` itself:
+
+
+# 10:06:32 >  
+# 10:06:32 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=34205" "--set" 
"mapi_usock=/var/tmp/mtest-22741/.s.monetdb.34205" "--set" "monet_prompt=" 
"--forcemito" "--set" "mal_listing=2" 
"--dbpath=/home/niels/scratch/rc-clean/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2013"
 "--set" "mal_listing=0"
+# 10:06:32 >  
+
+# MonetDB 5 server v11.15.12
+# This is an unreleased version
+# Serving database 'mTests_sql_test_BugTracker-2013', using 4 threads
+# Compiled for x86_64-unknown-linux-gnu/64bit with 64bit OIDs dynamically 
linked
+# Found 3.775 GiB available main-memory.
+# Copyright (c) 1993-July 2008 CWI.
+# Copyright (c) August 2008-2013 MonetDB B.V., all rights reserved
+# Visit http://www.monetdb.org/ for further information
+# Listening for connection requests on 
mapi:monetdb://niels.nesco.mine.nu:34205/
+# Listening for UNIX domain connection requests on 
mapi:monetdb:///var/tmp/mtest-22741/.s.monetdb.34205
+# MonetDB/GIS module loaded
+# MonetDB/JAQL module loaded
+# MonetDB/SQL module loaded
+
+Ready.
+
+# 10:06:32 >  
+# 10:06:32 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-22741" "--port=34205"
+# 10:06:32 >  
+
+#create table x (s string);
+#insert into x values('%able%');
+[ 1    ]
+#select * from sys._tables, x where name like s;
+% sys._tables, sys._tables,    sys._tables,    sys._tables,    sys._tables,    
sys._tables,    sys._tables,    sys._tables,    sys.x # table_name
+% id,  name,   schema_id,      query,  type,   system, commit_action,  
readonly,       s # name
+% int, varchar,        int,    varchar,        smallint,       boolean,        
smallint,       boolean,        clob # type
+% 4,   35,     4,      496,    1,      5,      1,      5,      6 # length
+[ 2055,        "_tables",      2000,   NULL,   0,      true,   0,      false,  
"%able%"        ]
+[ 2103,        "_tables",      2102,   NULL,   0,      true,   2,      false,  
"%able%"        ]
+[ 5075,        "tables",       2000,   "SELECT * FROM (SELECT p.*, 0 AS 
\"temporary\" FROM \"sys\".\"_tables\" AS p UNION ALL SELECT t.*, 1 AS 
\"temporary\" FROM \"tmp\".\"_tables\" AS t) AS tables where tables.type <> 
2;",        1,      true,   0,      false,  "%able%"        ]
+[ 5405,        "#dependencies_tables_on_views",        2000,   NULL,   2,      
true,   0,      false,  "%able%"        ]
+[ 5412,        "#dependencies_tables_on_indexes",      2000,   NULL,   2,      
true,   0,      false,  "%able%"        ]
+[ 5419,        "#dependencies_tables_on_triggers",     2000,   NULL,   2,      
true,   0,      false,  "%able%"        ]
+[ 5426,        "#dependencies_tables_on_foreignkeys",  2000,   NULL,   2,      
true,   0,      false,  "%able%"        ]
+[ 5433,        "#dependencies_tables_on_functions",    2000,   NULL,   2,      
true,   0,      false,  "%able%"        ]
+[ 6115,        "tablestoragemodel",    2000,   "-- A summary of the table 
storage requirement is is available as a table view.\n-- The auxillary column 
denotes the maximum space if all non-sorted columns\n-- would be augmented with 
a hash (rare situation)\ncreate view sys.tablestoragemodel\nas select 
\"schema\",\"table\",max(count) as \"count\",\n\tsum(columnsize) as 
columnsize,\n\tsum(heapsize) as heapsize,\n\tsum(indices) as 
indices,\n\tsum(case when sorted = false then 8 * count else 0 end) as 
auxillary\nfrom sys.storagemodel() group by \"schema\",\"table\";",      1,     
 true,   0,      false,  "%able%"        ]
+#drop table x;
+
+# 10:06:32 >  
+# 10:06:32 >  "Done."
+# 10:06:32 >  
+
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to