Changeset: 6f55a1e7f893 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6f55a1e7f893 Added Files: sql/test/BugTracker-2016/Tests/projectionpath-prefix.Bug.sql sql/test/BugTracker-2016/Tests/projectionpath-prefix.Bug.stable.err sql/test/BugTracker-2016/Tests/projectionpath-prefix.Bug.stable.out sql/test/BugTracker-2016/Tests/storagemodel.Bug-3923.sql sql/test/BugTracker-2016/Tests/storagemodel.Bug-3923.stable.err sql/test/BugTracker-2016/Tests/storagemodel.Bug-3923.stable.out Modified Files: monetdb5/mal/mal_instruction.c monetdb5/optimizer/opt_profiler.c monetdb5/optimizer/opt_projectionpath.c sql/test/BugTracker-2016/Tests/All Branch: embedded Log Message:
merge with default diffs (truncated from 501 to 300 lines): diff --git a/monetdb5/mal/mal_instruction.c b/monetdb5/mal/mal_instruction.c --- a/monetdb5/mal/mal_instruction.c +++ b/monetdb5/mal/mal_instruction.c @@ -1088,6 +1088,8 @@ clearVariable(MalBlkPtr mb, int varid) return; if (v->name) GDKfree(v->name); + if (v->stc) + GDKfree(v->stc); if (isVarConstant(mb, varid) || isVarDisabled(mb, varid)) VALclear(&v->value); v->name = 0; @@ -1096,6 +1098,7 @@ clearVariable(MalBlkPtr mb, int varid) v->tmpindex = 0; v->rowcnt = 0; v->eolife = 0; + v->stc = 0; } void diff --git a/monetdb5/optimizer/opt_profiler.c b/monetdb5/optimizer/opt_profiler.c --- a/monetdb5/optimizer/opt_profiler.c +++ b/monetdb5/optimizer/opt_profiler.c @@ -85,19 +85,19 @@ OPTprofilerImplementation(Client cntxt, // inherit property of first argument v = getSTC(mb,getArg(p,1)); if(v != NULL) - setSTC(mb, getArg(p,0),GDKstrdup(buf)); + setSTC(mb, getArg(p,0),GDKstrdup(v)); } else if( getModuleId(p)== algebraRef && getFunctionId(p)== projectionRef){ // inherit property of last argument v = getSTC(mb,getArg(p,p->argc-1)); if( v != NULL) - setSTC(mb, getArg(p,0), GDKstrdup(buf)); + setSTC(mb, getArg(p,0), GDKstrdup(v)); } else if( getModuleId(p)== algebraRef && getFunctionId(p)== subjoinRef){ // inherit property of last argument v = getSTC(mb,getArg(p,p->argc-1) ); if( v != NULL) - setSTC(mb, getArg(p,0), GDKstrdup(buf)); + setSTC(mb, getArg(p,0), GDKstrdup(v)); } } return 1; diff --git a/monetdb5/optimizer/opt_projectionpath.c b/monetdb5/optimizer/opt_projectionpath.c --- a/monetdb5/optimizer/opt_projectionpath.c +++ b/monetdb5/optimizer/opt_projectionpath.c @@ -8,7 +8,6 @@ /* author: M Kersten * Post-optimization of projection lists. - * The algorithm is quadratic in the number of paths considered. */ #include "monetdb_config.h" #include "opt_deadcode.h" @@ -17,12 +16,18 @@ //#undef OPTDEBUGprojectionpath //#define OPTDEBUGprojectionpath if(1) +#define ELIMCOMMONPREFIX + #define LOOKAHEAD 500 /* limit the lookahead for candidates */ -/* locate common prefixes in projection lists */ + +/* locate common prefixes in projection lists + * The algorithm is quadratic in the number of paths considered. */ + +#ifdef ELIMCOMMONPREFIX static int OPTprojectionPrefix(Client cntxt, MalBlkPtr mb, int prefixlength) { - int i, j, k, match, actions=0; + int i, j, k, match, actions=0; InstrPtr p,q,r,*old; int limit, slimit; @@ -72,6 +77,8 @@ OPTprojectionPrefix(Client cntxt, MalBlk r->argc = prefixlength; getArg(r,0) = newTmpVariable(mb, newBatType( TYPE_oid, getColumnType(getArgType(mb,r,r->argc-1)))); setVarUDFtype(mb, getArg(r,0)); + if( r->argc == 3) + setFunctionId(r,projectionRef); pushInstruction(mb,r); OPTDEBUGprojectionpath { mnstr_printf(cntxt->fdout,"#projectionpath prefix instruction\n"); @@ -99,6 +106,8 @@ OPTprojectionPrefix(Client cntxt, MalBlk getArg(q,q->retc) = getArg(r,0); for( k= q->retc +1 ; k < prefixlength; k++) delArgument(q, q->retc + 1); + if( q->argc == 3) + setFunctionId(q,projectionRef); } OPTDEBUGprojectionpath { mnstr_printf(cntxt->fdout,"#projectionpath after :"); @@ -115,22 +124,9 @@ OPTprojectionPrefix(Client cntxt, MalBlk getArg(p,p->retc) = getArg(r,0); for( k= p->retc + 1; k < prefixlength; k++) delArgument(p, p->retc + 1); + if( p->argc == 3) + setFunctionId(p,projectionRef); } - /* Finally check if we already have this prefix operation then an alias is sufficient - for( jj= i-1; jj > 0 && jj > i - LOOKAHEAD; jj--) { - q= old[jj]; - if ( getFunctionId(q) != getFunctionId(r) || q->argc != r->argc) - continue; - for( match =0, k = q->retc; k < q->argc; k++) - match += getArg(q,k) == getArg(r,k); - if ( match && match == q->argc - q->retc){ - clrFunction(r); - r->argc = r->retc +1; - getArg(r,r->retc) = getArg(q,0); - break; - } - } - */ OPTDEBUGprojectionpath printInstruction(cntxt->fdout,mb, 0, p, LIST_MAL_ALL); @@ -150,6 +146,7 @@ OPTprojectionPrefix(Client cntxt, MalBlk actions += OPTdeadcodeImplementation(cntxt, mb, 0, 0); return actions; } +#endif int OPTprojectionpathImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p) @@ -288,14 +285,22 @@ OPTprojectionpathImplementation(Client c /* All complete projection paths have been constructed. * There may be cases where there is a common prefix used multiple times. - * There are located and removed in a few scans over the plan + * They are located and removed in a few scans over the plan + * + * The prefix path mostly consist of smaller columns, + * which make the benefit not large. In SF100 roughly 100 out of + * 4500 projection operations were removed. + * On medium scale databases it may save cpu cycles. + * Turning this feature into a compile time option. */ +#ifdef ELIMCOMMONPREFIX if( maxprefixlength > 3){ /* Before searching the prefix, we should remove all non-used instructions. */ actions += OPTdeadcodeImplementation(cntxt, mb, 0, 0); for( ; maxprefixlength > 2; maxprefixlength--) actions += OPTprojectionPrefix(cntxt, mb, maxprefixlength); } +#endif OPTDEBUGprojectionpath { mnstr_printf(cntxt->fdout,"#projectionpath optimizer result \n"); printFunction(cntxt->fdout,mb, 0, LIST_MAL_ALL); diff --git a/sql/test/BugTracker-2016/Tests/All b/sql/test/BugTracker-2016/Tests/All --- a/sql/test/BugTracker-2016/Tests/All +++ b/sql/test/BugTracker-2016/Tests/All @@ -1,4 +1,6 @@ +storagemodel.Bug-3923 LEFT-JOIN_with_OR_conditions_triggers_assertion.Bug-3908 incorrect_column_name_in_OR_condition_of_LEFT-JOIN_crashes_mserver.Bug-3909 DISTINCT_with_correlated_scalar_subquery_crashes_mserver.Bug-3920 create_table_from_complex_query.Bug-3921 +projectionpath-prefix.Bug diff --git a/sql/test/BugTracker-2016/Tests/projectionpath-prefix.Bug.sql b/sql/test/BugTracker-2016/Tests/projectionpath-prefix.Bug.sql new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2016/Tests/projectionpath-prefix.Bug.sql @@ -0,0 +1,15 @@ +CREATE TABLE bar (name CHAR(8) PRIMARY KEY); +CREATE TABLE foo (id INTEGER, barname CHAR(8)); +ALTER TABLE foo ADD CONSTRAINT "fname" FOREIGN KEY ("barname") +REFERENCES bar ("name") ON DELETE CASCADE; + +SELECT ps.name, pkt.name, pkkc.name, fkkc.name, fkkc.nr, fkk.name, +fkk."action", fs.name, fkt.name FROM sys._tables fkt, sys.objects fkkc, +sys.keys fkk, sys._tables pkt, sys.objects pkkc, sys.keys pkk, +sys.schemas ps, sys.schemas fs WHERE fkt.id = fkk.table_id AND pkt.id = +pkk.table_id AND fkk.id = fkkc.id AND pkk.id = pkkc.id AND fkk.rkey = +pkk.id AND fkkc.nr = pkkc.nr AND pkt.schema_id = ps.id AND fkt.schema_id += fs.id AND fkt.system = FALSE ORDER BY fs.name,fkt.name, fkk.name, nr; + +DROP TABLE foo; +DROP TABLE bar; diff --git a/sql/test/BugTracker-2016/Tests/projectionpath-prefix.Bug.stable.err b/sql/test/BugTracker-2016/Tests/projectionpath-prefix.Bug.stable.err new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2016/Tests/projectionpath-prefix.Bug.stable.err @@ -0,0 +1,35 @@ +stderr of test 'projectionpath-prefix.Bug` in directory 'sql/test/BugTracker-2016` itself: + + +# 10:56:46 > +# 10:56:46 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "mapi_open=true" "--set" "mapi_port=39911" "--set" "mapi_usock=/var/tmp/mtest-21202/.s.monetdb.39911" "--set" "monet_prompt=" "--forcemito" "--dbpath=/export/scratch1/mk/default//Linux/var/MonetDB/mTests_sql_test_BugTracker-2016" "--set" "embedded_r=yes" +# 10:56:46 > + +# builtin opt gdk_dbpath = /export/scratch1/mk/default//Linux/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 = 39911 +# cmdline opt mapi_usock = /var/tmp/mtest-21202/.s.monetdb.39911 +# cmdline opt monet_prompt = +# cmdline opt gdk_dbpath = /export/scratch1/mk/default//Linux/var/MonetDB/mTests_sql_test_BugTracker-2016 +# cmdline opt embedded_r = yes +# cmdline opt gdk_debug = 536870922 + +# 10:56:46 > +# 10:56:46 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" "--host=/var/tmp/mtest-21202" "--port=39911" +# 10:56:46 > + + +# 10:56:46 > +# 10:56:46 > "Done." +# 10:56:46 > + diff --git a/sql/test/BugTracker-2016/Tests/projectionpath-prefix.Bug.stable.out b/sql/test/BugTracker-2016/Tests/projectionpath-prefix.Bug.stable.out new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2016/Tests/projectionpath-prefix.Bug.stable.out @@ -0,0 +1,54 @@ +stdout of test 'projectionpath-prefix.Bug` in directory 'sql/test/BugTracker-2016` itself: + + +# 10:56:46 > +# 10:56:46 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "mapi_open=true" "--set" "mapi_port=39911" "--set" "mapi_usock=/var/tmp/mtest-21202/.s.monetdb.39911" "--set" "monet_prompt=" "--forcemito" "--dbpath=/export/scratch1/mk/default//Linux/var/MonetDB/mTests_sql_test_BugTracker-2016" "--set" "embedded_r=yes" +# 10:56:46 > + +# MonetDB 5 server v11.22.0 +# This is an unreleased version +# Serving database 'mTests_sql_test_BugTracker-2016', using 8 threads +# Compiled for x86_64-unknown-linux-gnu/64bit with 64bit OIDs and 128bit integers dynamically linked +# Found 15.589 GiB available main-memory. +# Copyright (c) 1993-July 2008 CWI. +# Copyright (c) August 2008-2015 MonetDB B.V., all rights reserved +# Visit http://www.monetdb.org/ for further information +# Listening for connection requests on mapi:monetdb://vienna.da.cwi.nl:39911/ +# Listening for UNIX domain connection requests on mapi:monetdb:///var/tmp/mtest-21202/.s.monetdb.39911 +# MonetDB/GIS module loaded +# Start processing logs sql/sql_logs version 52200 +# Start reading the write-ahead log 'sql_logs/sql/log.6' +# Finished reading the write-ahead log 'sql_logs/sql/log.6' +# Finished processing logs sql/sql_logs +# MonetDB/SQL module loaded +# MonetDB/R module loaded + +Ready. + +# 10:56:46 > +# 10:56:46 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" "--host=/var/tmp/mtest-21202" "--port=39911" +# 10:56:46 > + +#CREATE TABLE bar (name CHAR(8) PRIMARY KEY); +#CREATE TABLE foo (id INTEGER, barname CHAR(8)); +#ALTER TABLE foo ADD CONSTRAINT "fname" FOREIGN KEY ("barname") +#REFERENCES bar ("name") ON DELETE CASCADE; +#SELECT ps.name, pkt.name, pkkc.name, fkkc.name, fkkc.nr, fkk.name, +#fkk."action", fs.name, fkt.name FROM sys._tables fkt, sys.objects fkkc, +#sys.keys fkk, sys._tables pkt, sys.objects pkkc, sys.keys pkk, +#sys.schemas ps, sys.schemas fs WHERE fkt.id = fkk.table_id AND pkt.id = +#pkk.table_id AND fkk.id = fkkc.id AND pkk.id = pkkc.id AND fkk.rkey = +#pkk.id AND fkkc.nr = pkkc.nr AND pkt.schema_id = ps.id AND fkt.schema_id +#= fs.id AND fkt.system = FALSE ORDER BY fs.name,fkt.name, fkk.name, nr; +% sys.ps, sys.pkt, sys.pkkc, sys.fkkc, sys.fkkc, sys.fkk, sys.fkk, sys.fs, sys.fkt # table_name +% name, name, name, name, nr, name, action, name, name # name +% varchar, varchar, varchar, varchar, int, varchar, int, varchar, varchar # type +% 3, 3, 4, 7, 1, 13, 2, 3, 3 # length +[ "sys", "bar", "name", "barname", 0, "fname", -1, "sys", "foo" ] +#DROP TABLE foo; +#DROP TABLE bar; + +# 10:56:46 > +# 10:56:46 > "Done." +# 10:56:46 > + diff --git a/sql/test/BugTracker-2016/Tests/storagemodel.Bug-3923.sql b/sql/test/BugTracker-2016/Tests/storagemodel.Bug-3923.sql new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2016/Tests/storagemodel.Bug-3923.sql @@ -0,0 +1,26 @@ +-- platform dependent script test. +create table bug3923(i integer); + +select * from storage() where "table"= '_tables'; + +call storagemodelinit(); +update storagemodelinput set "count" =10000 where "table" ='bug3923'; +update storagemodelinput set "distinct" =10 where "table" ='bug3923' and "column" ='i'; + +select * from storagemodel() where "table" = 'bug3923'; + +drop table bug3923; + _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list