Changeset: 84bc1802d33d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=84bc1802d33d
Added Files:
        
sql/test/BugTracker-2016/Tests/column_name_lost_in_in_operator.Bug-6123.sql
        
sql/test/BugTracker-2016/Tests/column_name_lost_in_in_operator.Bug-6123.stable.err
        
sql/test/BugTracker-2016/Tests/column_name_lost_in_in_operator.Bug-6123.stable.out
Modified Files:
        monetdb5/optimizer/opt_multiplex.c
        monetdb5/optimizer/opt_pushselect.c
        monetdb5/optimizer/opt_wrapper.c
        sql/backends/monet5/sql_execute.c
        sql/backends/monet5/sql_optimizer.c
        sql/server/rel_select.c
        sql/test/BugTracker-2016/Tests/All
Branch: default
Log Message:

Merge with Dec2016 branch.


diffs (truncated from 739 to 300 lines):

diff --git a/monetdb5/optimizer/opt_multiplex.c 
b/monetdb5/optimizer/opt_multiplex.c
--- a/monetdb5/optimizer/opt_multiplex.c
+++ b/monetdb5/optimizer/opt_multiplex.c
@@ -260,7 +260,8 @@ OPTmultiplexImplementation(Client cntxt,
        GDKfree(msg);
 
     /* Defense line against incorrect plans */
-    if( mb->errors == 0 && actions > 0){ chkTypes(cntxt->fdout, cntxt->nspace, 
mb, FALSE);
+    if( mb->errors == 0 && actions > 0){
+        chkTypes(cntxt->fdout, cntxt->nspace, mb, FALSE);
         chkFlow(cntxt->fdout, mb);
         chkDeclarations(cntxt->fdout, mb);
     }
diff --git a/monetdb5/optimizer/opt_pushselect.c 
b/monetdb5/optimizer/opt_pushselect.c
--- a/monetdb5/optimizer/opt_pushselect.c
+++ b/monetdb5/optimizer/opt_pushselect.c
@@ -606,6 +606,7 @@ OPTpushselectImplementation(Client cntxt
         chkFlow(cntxt->fdout, mb);
         chkDeclarations(cntxt->fdout, mb);
     }
+wrapup:
     /* keep all actions taken as a post block comment */
 wrapup:
     snprintf(buf,256,"%-20s actions=%2d time=" LLFMT " 
usec","pushselect",actions,GDKusec() - usec);
diff --git a/monetdb5/optimizer/opt_wrapper.c b/monetdb5/optimizer/opt_wrapper.c
--- a/monetdb5/optimizer/opt_wrapper.c
+++ b/monetdb5/optimizer/opt_wrapper.c
@@ -156,7 +156,8 @@ str OPTwrapper (Client cntxt, MalBlkPtr 
                ((sizeof( MalBlkRecord) +mb->ssize * offsetof(InstrRecord, 
argv)+ mb->vtop * sizeof(int) /* argv estimate */ +mb->vtop* sizeof(VarRecord) 
+ mb->vsize*sizeof(VarPtr)+1023)/1024),
                usec);
        QOTupdateStatistics(curmodnme,actions,usec);
-       addtoMalBlkHistory(mb);
+       if( actions)
+               addtoMalBlkHistory(mb);
        if ( mb->errors)
                throw(MAL, optimizer, PROGRAM_GENERAL ":%s.%s", modnme, fcnnme);
        return MAL_SUCCEED;
diff --git a/sql/backends/monet5/sql_execute.c 
b/sql/backends/monet5/sql_execute.c
--- a/sql/backends/monet5/sql_execute.c
+++ b/sql/backends/monet5/sql_execute.c
@@ -271,6 +271,8 @@ SQLrun(Client c, backend *be, mvc *m){
                return createException(PARSE, "SQLparser", "%s", m->errstr);
        // locate and inline the query template instruction
        mb = copyMalBlk(c->curprg->def);
+       mb->history = c->curprg->def->history;
+       c->curprg->def->history =0;
 
        /* only consider a re-optimization when we are dealing with query 
templates */
        for ( i= 1; i < mb->stop;i++){
diff --git a/sql/backends/monet5/sql_optimizer.c 
b/sql/backends/monet5/sql_optimizer.c
--- a/sql/backends/monet5/sql_optimizer.c
+++ b/sql/backends/monet5/sql_optimizer.c
@@ -171,6 +171,7 @@ addOptimizers(Client c, MalBlkPtr mb, ch
        if (msg){
                return msg;
        }
+       mb->keephistory |= be->mvc->emod & mod_debug;
        if (be->mvc->no_mitosis) {
                for (i = mb->stop - 1; i > 0; i--) {
                        q = getInstrPtr(mb, i);
@@ -200,7 +201,7 @@ SQLoptimizeFunction(Client c, MalBlkPtr 
        msg = addOptimizers(c, mb, pipe, TRUE);
        if (msg)
                return msg;
-       mb->keephistory = be->mvc->emod & mod_debug;
+       mb->keephistory |= be->mvc->emod & mod_debug;
        msg = optimizeMALBlock(c, mb);
        mb->keephistory = FALSE;
        return msg;
@@ -249,6 +250,7 @@ SQLoptimizeQuery(Client c, MalBlkPtr mb)
        msg = addOptimizers(c, mb, pipe, FALSE);
        if (msg)
                return msg;
+       mb->keephistory |= be->mvc->emod & mod_debug;
        msg = optimizeMALBlock(c, mb);
        return msg;
 }
diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c
--- a/sql/server/rel_select.c
+++ b/sql/server/rel_select.c
@@ -1993,16 +1993,21 @@ rel_logical_value_exp(mvc *sql, sql_rel 
                dlist *dl = sc->data.lval;
                symbol *lo = dl->h->data.sym;
                dnode *n = dl->h->next;
-               sql_exp *l = rel_value_exp(sql, rel, lo, f, ek), *r = NULL;
-               sql_rel *left = NULL, *right = NULL;
+               sql_rel *left = NULL, *right = NULL, *outer = *rel;
+               sql_exp *l = NULL, *r = NULL;
                int needproj = 0, vals_only = 1;
-               list *vals = NULL;
-
+               list *vals = NULL, *pexps = NULL;
+
+               if (outer && f == sql_sel && is_project(outer->op) && 
!is_processed(outer) && outer->l && !list_empty(outer->exps)) {
+                       needproj = 1;
+                       pexps = outer->exps;
+                       *rel = outer->l;
+               }
+
+               l = rel_value_exp(sql, rel, lo, f, ek);
                if (!l)
                        return NULL;
-
                ek.card = card_set;
-
                if (!left)
                        left = *rel;
 
@@ -2010,7 +2015,6 @@ rel_logical_value_exp(mvc *sql, sql_rel 
                        needproj = (left != NULL);
                        left = rel_project_exp(sql->sa, l);
                }
-
                if (left && is_project(left->op) && list_empty(left->exps))
                        left = left->l;
 
@@ -2076,6 +2080,7 @@ rel_logical_value_exp(mvc *sql, sql_rel 
                                                e = rel_binop_(sql, e, ne, 
NULL, "or", card_value);
                                        }
                                }
+                               *rel = outer;
                                return e;
                        }
                        r = rel_lastexp(sql, right);
@@ -2087,7 +2092,7 @@ rel_logical_value_exp(mvc *sql, sql_rel 
                        e = exp_compare(sql->sa, l, r, cmp_equal );
                        rel_join_add_exp(sql->sa, left, e);
                        if (*rel && needproj)
-                               left = *rel = rel_project(sql->sa, left, NULL);
+                               left = *rel = rel_project(sql->sa, left, pexps);
                        else
                                *rel = left;
                        if (sc->token == SQL_NOT_IN)
@@ -2514,9 +2519,6 @@ rel_logical_exp(mvc *sql, sql_rel *rel, 
                        if (!correlated) {
                                if (right->processed)
                                        right = rel_label(sql, right, 0);
-                               /*
-                               right = rel_distinct(right);
-                               */
                        }
                } else {
                        return sql_error(sql, 02, "IN: missing inner query");
@@ -2539,13 +2541,10 @@ rel_logical_exp(mvc *sql, sql_rel *rel, 
                                sql_exp *l = n->data;
                                sql_exp *r = m->data;
 
-                               //r = rel_lastexp(sql, right);
-                               //r = exp_column(sql->sa, exp_relname(r), 
exp_name(r), exp_subtype(r), exp_card(r), has_nil(r), is_intern(r));
                                r = exp_alias_or_copy(sql, exp_relname(r), 
exp_name(r), right, r);
                                if (rel_convert_types(sql, &l, &r, 1, 
type_equal) < 0) 
                                        return NULL;
                                e = exp_compare(sql->sa, l, r, cmp_equal );
-                               //rel_join_add_exp(sql->sa, rel, e);
                                append(jexps, e);
                        }
                        if (correlated && l_is_value) {
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
@@ -69,3 +69,4 @@ case-column-when-null-Bug-6124
 select-in-from.Bug-6119
 select-in-from.Bug-6121
 nested-subquery-in-select.Bug-6125
+column_name_lost_in_in_operator.Bug-6123
diff --git 
a/sql/test/BugTracker-2016/Tests/column_name_lost_in_in_operator.Bug-6123.sql 
b/sql/test/BugTracker-2016/Tests/column_name_lost_in_in_operator.Bug-6123.sql
new file mode 100644
--- /dev/null
+++ 
b/sql/test/BugTracker-2016/Tests/column_name_lost_in_in_operator.Bug-6123.sql
@@ -0,0 +1,274 @@
+
+/* Relations */
+CREATE TABLE comments(
+    id BIGINT NOT NULL PRIMARY KEY,
+    creationDate TIMESTAMP(3) WITH TIME ZONE NOT NULL,
+    locationIP VARCHAR(40) NOT NULL,
+    browserUsed VARCHAR(40) NOT NULL,
+    content VARCHAR(2000) NOT NULL,
+    length INT NOT NULL,
+    creator BIGINT NOT NULL,
+    place_id BIGINT NOT NULL,
+    replyOfPost BIGINT,
+    replyOfComment BIGINT
+);
+
+CREATE TABLE comment_tags(
+    comment_id BIGINT NOT NULL,
+    tag_id BIGINT NOT NULL,
+    PRIMARY KEY(comment_id, tag_id)
+);
+
+CREATE TABLE forums(
+    id BIGINT NOT NULL PRIMARY KEY,
+    title VARCHAR(80) NOT NULL,
+    creationDate TIMESTAMP(3) WITH TIME ZONE NOT NULL,
+    moderator BIGINT /*though it seems that all generated tuples have always a 
moderator */
+);
+
+CREATE TABLE forum_persons(
+    forum_id BIGINT NOT NULL,
+    person_id BIGINT NOT NULL,
+    joinDate TIMESTAMP(3) WITH TIME ZONE NOT NULL,
+    PRIMARY KEY(forum_id, person_id)
+);
+
+CREATE TABLE forum_tags(
+    forum_id BIGINT NOT NULL,
+    tag_id BIGINT NOT NULL,
+    PRIMARY KEY(forum_id, tag_id)
+);
+
+CREATE TABLE friends(
+    src BIGINT NOT NULL,
+    dst BIGINT NOT NULL,
+    creationDate TIMESTAMP(3) WITH TIME ZONE NOT NULL,
+    PRIMARY KEY(src, dst)
+);
+
+CREATE TABLE organisations(
+    id BIGINT NOT NULL PRIMARY KEY,
+    "type" VARCHAR(40) NOT NULL, /* university or company */
+    name VARCHAR(160) NOT NULL,
+    url VARCHAR(2000) NOT NULL,
+    place_id BIGINT NOT NULL
+);
+
+CREATE TABLE persons(
+    id BIGINT NOT NULL PRIMARY KEY,
+    firstName VARCHAR(40) NOT NULL ,
+    lastName VARCHAR(40) NOT NULL,
+    gender VARCHAR(40) NOT NULL,
+    birthDay DATE NOT NULL,
+    creationDate TIMESTAMP(3) WITH TIME ZONE NOT NULL,
+    locationIP VARCHAR(40) NOT NULL,
+    browserUsed VARCHAR(40) NOT NULL,
+    place_id BIGINT NOT NULL
+);
+
+CREATE TABLE person_comments(
+    person_id BIGINT NOT NULL,
+    comment_id BIGINT NOT NULL,
+    creationDate TIMESTAMP(3) WITH TIME ZONE NOT NULL,
+    PRIMARY KEY(person_id, comment_id)
+);
+
+CREATE TABLE person_emails(
+    id BIGINT NOT NULL,
+    email VARCHAR(120) NOT NULL,
+    PRIMARY KEY(id, email)
+);
+
+CREATE TABLE person_languages(
+    id BIGINT NOT NULL,
+    "language" VARCHAR(40) NOT NULL,
+    PRIMARY KEY(id, "language")
+);
+
+CREATE TABLE person_tags(
+    person_id BIGINT NOT NULL,
+    tag_id BIGINT NOT NULL,
+    PRIMARY KEY(person_id, tag_id)
+);
+
+CREATE TABLE person_posts(
+    person_id BIGINT NOT NULL,
+    post_id BIGINT NOT NULL,
+    creationDate TIMESTAMP(3) WITH TIME ZONE NOT NULL,
+    PRIMARY KEY(person_id, post_id)
+);
+
+CREATE TABLE person_studyAt_organisations(
+    person_id BIGINT NOT NULL,
+    organisation_id BIGINT NOT NULL,
+    classYear INT NOT NULL,
+    PRIMARY KEY(person_id, organisation_id)
+);
+
+CREATE TABLE person_workAt_organisations(
+    person_id BIGINT NOT NULL,
+    organisation_id BIGINT NOT NULL,
+    workFrom INT NOT NULL,
+    PRIMARY KEY(person_id, organisation_id)
+);
+
+CREATE TABLE places(
+    id BIGINT NOT NULL PRIMARY KEY,
+    name VARCHAR(200) NOT NULL,
+    url VARCHAR(2000) NOT NULL, /* suspecting this is a left-over for RDF 
systems where this field replaces the ID */
+    "type" VARCHAR(40) NOT NULL, 
+    isPartOf BIGINT
+);
+
+CREATE TABLE posts(
+    id BIGINT NOT NULL PRIMARY KEY,
+    imageFile VARCHAR(40),
+    creationDate TIMESTAMP(3) WITH TIME ZONE NOT NULL,
+    locationIP VARCHAR(40) NOT NULL,
+    browserUsed VARCHAR(40) NOT NULL,
+    "language" VARCHAR(40),
+    content VARCHAR(2000),
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to