Changeset: a8cf0eefabec for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/a8cf0eefabec
Modified Files:
        sql/backends/monet5/sql.c
        sql/server/rel_optimizer.c
Branch: default
Log Message:

Merged with Jan2022


diffs (truncated from 312 to 300 lines):

diff --git a/common/utils/mutils.c b/common/utils/mutils.c
--- a/common/utils/mutils.c
+++ b/common/utils/mutils.c
@@ -590,6 +590,7 @@ MT_stat(const char *pathname, struct _st
 }
 
 #define RETRIES 10
+#define SLEEPTIME 20
 
 int
 MT_rmdir(const char *pathname)
@@ -607,7 +608,7 @@ MT_rmdir(const char *pathname)
                 * service which prevents us from doing what we have a
                 * right to do, so try again (once) */
 //             fprintf(stderr, "#Retry rmdir %s\n", pathname);
-               Sleep(10);      /* wait a little */
+               Sleep(SLEEPTIME);       /* wait a little */
        }
        free(wpathname);
        return ret;
@@ -627,7 +628,7 @@ WMT_remove(const wchar_t *wpathname)
                 * service which prevents us from doing what we have a
                 * right to do, so try again (once) */
 //             fprintf(stderr, "#Retry unlink %ls\n", wpathname);
-               Sleep(10);      /* wait a little */
+               Sleep(SLEEPTIME);       /* wait a little */
        }
        return ret;
 }
@@ -668,7 +669,7 @@ MT_rename(const char *old, const char *d
                         * service which prevents us from doing what we have a
                         * right to do, so try again (once) */
 //                     fprintf(stderr, "#Retry rename %s %s\n", old, dst);
-                       Sleep(10);      /* wait a little */
+                       Sleep(SLEEPTIME);       /* wait a little */
                }
        }
        free(wold);
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -4961,6 +4961,8 @@ SQLstr_column_vacuum(Client cntxt, MalBl
        if (!isTable(t))
                throw(SQL, "sql.str_column_vacuum", SQLSTATE(42000) "%s '%s' is 
not persistent",
                          TABLE_TYPE_DESCRIPTION(t->type, t->properties), 
t->base.name);
+       if (isTempTable(t))
+               throw(SQL, "sql.str_column_vacuum", SQLSTATE(42000) "Cannot 
vaccum column from temporary table");
        if ((c = mvc_bind_column(m, t, cname)) == NULL)
                throw(SQL, "sql.str_column_vacuum", SQLSTATE(42S22) "Column not 
found %s.%s",sname,tname);
        if (c->storage_type)
@@ -5096,6 +5098,8 @@ SQLstr_column_auto_vacuum(Client cntxt, 
        if (!isTable(t))
                throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42000) "%s 
'%s' is not persistent",
                          TABLE_TYPE_DESCRIPTION(t->type, t->properties), 
t->base.name);
+       if (isTempTable(t))
+               throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42000) 
"Cannot vaccum column from temporary table");
        if ((c = mvc_bind_column(m, t, cname)) == NULL)
                throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42S22) 
"Column not found %s.%s",sname,tname);
        if (c->storage_type)
@@ -5137,18 +5141,20 @@ SQLstr_column_stop_vacuum(Client cntxt, 
        sql_column *c = NULL;
 
        if (strNil(sname))
-               throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42000) 
"Schema name cannot be NULL");
+               throw(SQL, "sql.str_column_stop_vacuum", SQLSTATE(42000) 
"Schema name cannot be NULL");
        if (strNil(tname))
-               throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42000) "Table 
name cannot be NULL");
+               throw(SQL, "sql.str_column_stop_vacuum", SQLSTATE(42000) "Table 
name cannot be NULL");
        if (strNil(cname))
-               throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42000) 
"Column name cannot be NULL");
+               throw(SQL, "sql.str_column_stop_vacuum", SQLSTATE(42000) 
"Column name cannot be NULL");
        if ((s = mvc_bind_schema(m, sname)) == NULL)
                throw(SQL, "sql.str_column_stop_vacuum", SQLSTATE(3F000) 
"Invalid or missing schema %s",sname);
        if ((t = mvc_bind_table(m, s, tname)) == NULL)
                throw(SQL, "sql.str_column_stop_vacuum", SQLSTATE(42S02) 
"Invalid or missing table %s.%s",sname,tname);
        if (!isTable(t))
-               throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42000) "%s 
'%s' is not persistent",
+               throw(SQL, "sql.str_column_stop_vacuum", SQLSTATE(42000) "%s 
'%s' is not persistent",
                          TABLE_TYPE_DESCRIPTION(t->type, t->properties), 
t->base.name);
+       if (isTempTable(t))
+               throw(SQL, "sql.str_column_stop_vacuum", SQLSTATE(42000) 
"Cannot vaccum column from temporary table");
        if ((c = mvc_bind_column(m, t, cname)) == NULL)
                throw(SQL, "sql.str_column_stop_vacuum", SQLSTATE(42S22) 
"Column not found %s.%s",sname,tname);
 
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
@@ -149,7 +149,7 @@ name_find_column( sql_rel *rel, const ch
                        alias = exps_bind_column2(rel->exps, rname, name, NULL);
                else
                        alias = exps_bind_column(rel->exps, name, NULL, NULL, 
1);
-               if (is_groupby(rel->op) && alias && alias->type == e_column && 
rel->r) {
+               if (is_groupby(rel->op) && alias && alias->type == e_column && 
!list_empty(rel->r)) {
                        if (alias->l)
                                alias = exps_bind_column2(rel->r, alias->l, 
alias->r, NULL);
                        else
@@ -1921,10 +1921,10 @@ rel_push_topn_and_sample_down(visitor *v
                        return rel;
 
                /* push topn/sample under projections */
-               if (!rel_is_ref(rel) && r && is_simple_project(r->op) && 
!need_distinct(r) && !rel_is_ref(r) && r->l && !r->r) {
+               if (!rel_is_ref(rel) && r && is_simple_project(r->op) && 
!need_distinct(r) && !rel_is_ref(r) && r->l && list_empty(r->r)) {
                        sql_rel *x = r, *px = x;
 
-                       while (is_simple_project(x->op) && !need_distinct(x) && 
!rel_is_ref(x) && x->l && !x->r) {
+                       while (is_simple_project(x->op) && !need_distinct(x) && 
!rel_is_ref(x) && x->l && list_empty(x->r)) {
                                px = x;
                                x = x->l;
                        }
@@ -1947,7 +1947,7 @@ rel_push_topn_and_sample_down(visitor *v
                        bool changed = false;
 
                        x = ul;
-                       while (is_simple_project(x->op) && !need_distinct(x) && 
!rel_is_ref(x) && x->l && !x->r)
+                       while (is_simple_project(x->op) && !need_distinct(x) && 
!rel_is_ref(x) && x->l && list_empty(x->r))
                                x = x->l;
                        if (x && x->op != rel->op) { /* only push topn once */
                                ul = func(v->sql->sa, ul, 
sum_limit_offset(v->sql, rel));
@@ -1956,7 +1956,7 @@ rel_push_topn_and_sample_down(visitor *v
                        }
 
                        x = ur;
-                       while (is_simple_project(x->op) && !need_distinct(x) && 
!rel_is_ref(x) && x->l && !x->r)
+                       while (is_simple_project(x->op) && !need_distinct(x) && 
!rel_is_ref(x) && x->l && list_empty(x->r))
                                x = x->l;
                        if (x && x->op != rel->op) { /* only push topn once */
                                ur = func(v->sql->sa, ur, 
sum_limit_offset(v->sql, rel));
@@ -1972,33 +1972,27 @@ rel_push_topn_and_sample_down(visitor *v
                /* duplicate topn/sample + [ project-order ] under union */
                if (r)
                        rp = r->l;
-               if (r && r->exps && is_simple_project(r->op) && !rel_is_ref(r) 
&& r->r && r->l && is_union(rp->op)) {
-                       sql_rel *u = rp, *ou = u, *x;
-                       sql_rel *ul = u->l;
-                       sql_rel *ur = u->r;
-                       int add_r = 0;
+               if (r && r->exps && is_simple_project(r->op) && !rel_is_ref(r) 
&& !list_empty(r->r) && r->l && is_union(rp->op)) {
+                       sql_rel *u = rp, *ou = u, *x, *ul = u->l, *ur = u->r;
                        list *rcopy = NULL;
 
                        /* only push topn/sample once */
                        x = ul;
-                       while (is_simple_project(x->op) && !need_distinct(x) && 
!rel_is_ref(x) && x->l && !x->r)
+                       while (is_simple_project(x->op) && !need_distinct(x) && 
!rel_is_ref(x) && x->l && list_empty(x->r))
                                x = x->l;
                        if (x && x->op == rel->op)
                                return rel;
                        x = ur;
-                       while (is_simple_project(x->op) && !need_distinct(x) && 
!rel_is_ref(x) && x->l && !x->r)
+                       while (is_simple_project(x->op) && !need_distinct(x) && 
!rel_is_ref(x) && x->l && list_empty(x->r))
                                x = x->l;
                        if (x && x->op == rel->op)
                                return rel;
 
-                       if (list_length(ul->exps) > list_length(r->exps)) {
-                               add_r = 1;
-                               rcopy = exps_copy(v->sql, r->r);
-                               for (node *n = rcopy->h ; n ; n = n->next) {
-                                       sql_exp *e = n->data;
-                                       set_descending(e);
-                                       set_nulls_first(e);
-                               }
+                       rcopy = exps_copy(v->sql, r->r);
+                       for (node *n = rcopy->h ; n ; n = n->next) {
+                               sql_exp *e = n->data;
+                               set_descending(e); /* remove ordering 
properties for projected columns */
+                               set_nulls_first(e);
                        }
                        ul = rel_dup(ul);
                        ur = rel_dup(ur);
@@ -2015,8 +2009,7 @@ rel_push_topn_and_sample_down(visitor *v
                        ul = rel_project(v->sql->sa, ul, NULL);
                        ul->exps = exps_copy(v->sql, r->exps);
                        /* possibly add order by column */
-                       if (add_r)
-                               ul->exps = list_distinct(list_merge(ul->exps, 
exps_copy(v->sql, rcopy), NULL), (fcmp) exp_equal, (fdup) NULL);
+                       ul->exps = list_distinct(list_merge(ul->exps, 
exps_copy(v->sql, rcopy), NULL), (fcmp) exp_equal, (fdup) NULL);
                        ul->nrcols = list_length(ul->exps);
                        ul->r = exps_copy(v->sql, r->r);
                        ul = func(v->sql->sa, ul, sum_limit_offset(v->sql, 
rel));
@@ -2024,8 +2017,7 @@ rel_push_topn_and_sample_down(visitor *v
                        ur = rel_project(v->sql->sa, ur, NULL);
                        ur->exps = exps_copy(v->sql, r->exps);
                        /* possibly add order by column */
-                       if (add_r)
-                               ur->exps = list_distinct(list_merge(ur->exps, 
exps_copy(v->sql, rcopy), NULL), (fcmp) exp_equal, (fdup) NULL);
+                       ur->exps = list_distinct(list_merge(ur->exps, 
exps_copy(v->sql, rcopy), NULL), (fcmp) exp_equal, (fdup) NULL);
                        ur->nrcols = list_length(ur->exps);
                        ur->r = exps_copy(v->sql, r->r);
                        ur = func(v->sql->sa, ur, sum_limit_offset(v->sql, 
rel));
@@ -2035,8 +2027,7 @@ rel_push_topn_and_sample_down(visitor *v
                        u->nrcols = list_length(u->exps);
                        set_processed(u);
                        /* possibly add order by column */
-                       if (add_r)
-                               u->exps = list_distinct(list_merge(u->exps, 
rcopy, NULL), (fcmp) exp_equal, (fdup) NULL);
+                       u->exps = list_distinct(list_merge(u->exps, rcopy, 
NULL), (fcmp) exp_equal, (fdup) NULL);
                        if (need_distinct(r)) {
                                set_distinct(ul);
                                set_distinct(ur);
@@ -2123,7 +2114,7 @@ exp_push_down_prj(mvc *sql, sql_exp *e, 
                                return NULL;
                }
                /* possibly a groupby/project column is renamed */
-               if (is_groupby(f->op) && f->r) {
+               if (is_groupby(f->op) && !list_empty(f->r)) {
                        sql_exp *gbe = NULL;
                        if (ne->l)
                                gbe = exps_bind_column2(f->r, ne->l, ne->r, 
NULL);
@@ -2757,7 +2748,7 @@ rel_merge_projects(visitor *v, sql_rel *
        node *n;
 
        if (rel->op == op_project &&
-           prj && prj->op == op_project && !(rel_is_ref(prj)) && !prj->r) {
+           prj && prj->op == op_project && !(rel_is_ref(prj)) && 
list_empty(prj->r)) {
                int all = 1;
 
                if (project_unsafe(rel,0) || project_unsafe(prj,0) || 
exps_share_expensive_exp(rel->exps, prj->exps))
@@ -2792,7 +2783,7 @@ rel_merge_projects(visitor *v, sql_rel *
                if (all) {
                        /* we can now remove the intermediate project */
                        /* push order by expressions */
-                       if (rel->r) {
+                       if (!list_empty(rel->r)) {
                                list *nr = new_exp_list(v->sql->sa), *res = 
rel->r;
                                for (n = res->h; n; n = n->next) {
                                        sql_exp *e = n->data, *ne = NULL;
@@ -4183,7 +4174,7 @@ rel_push_aggr_down(visitor *v, sql_rel *
                        }
                }
 
-               if (rel->r) {
+               if (!list_empty(rel->r)) {
                        list *ogbe = rel->r;
 
                        gbe = new_exp_list(v->sql->sa);
@@ -5655,7 +5646,7 @@ rel_push_project_down_union(visitor *v, 
                v->changes++;
        }
 
-       if (rel->op == op_project && rel->l && rel->exps && !rel->r) {
+       if (rel->op == op_project && rel->l && rel->exps && list_empty(rel->r)) 
{
                int need_distinct = need_distinct(rel);
                sql_rel *u = rel->l;
                sql_rel *p = rel;
@@ -8004,7 +7995,7 @@ rel_split_project(visitor *v, sql_rel *r
                        if (nrel->l && !(nrel->l = rel_split_project(v, 
nrel->l, (is_topn(rel->op)||is_sample(rel->op))?top:0)))
                                return NULL;
                        return rel;
-               } else if (funcs && !top && !rel->r) {
+               } else if (funcs && !top && list_empty(rel->r)) {
                        /* projects can have columns point back into the 
expression list, ie
                         * create a new list including the split expressions */
                        node *n;
@@ -8013,7 +8004,7 @@ rel_split_project(visitor *v, sql_rel *r
                        rel->exps = sa_list(v->sql->sa);
                        for (n=exps->h; n; n = n->next)
                                append(rel->exps, split_exp(v->sql, n->data, 
rel));
-               } else if (funcs && top && rel_is_ref(rel) && !rel->r) {
+               } else if (funcs && top && rel_is_ref(rel) && 
list_empty(rel->r)) {
                        /* inplace */
                        list *exps = rel_projections(v->sql, rel, NULL, 1, 1);
                        sql_rel *l = rel_project(v->sql->sa, rel->l, NULL);
@@ -8122,7 +8113,7 @@ rel_split_select(visitor *v, sql_rel *re
                        if (nrel->l && !(nrel->l = rel_split_project(v, 
nrel->l, (is_topn(rel->op)||is_sample(rel->op))?top:0)))
                                return NULL;
                        return rel;
-               } else if (funcs && !top && !rel->r) {
+               } else if (funcs && !top && list_empty(rel->r)) {
                        /* projects can have columns point back into the 
expression list, ie
                         * create a new list including the split expressions */
                        node *n;
@@ -8131,7 +8122,7 @@ rel_split_select(visitor *v, sql_rel *re
                        rel->exps = sa_list(v->sql->sa);
                        for (n=exps->h; n; n = n->next)
                                append(rel->exps, select_split_exp(v->sql, 
n->data, rel));
-               } else if (funcs && top && rel_is_ref(rel) && !rel->r) {
+               } else if (funcs && top && rel_is_ref(rel) && 
list_empty(rel->r)) {
                        /* inplace */
                        list *exps = rel_projections(v->sql, rel, NULL, 1, 1);
                        sql_rel *l = rel_project(v->sql->sa, rel->l, NULL);
diff --git a/sql/test/SQLancer/Tests/sqlancer17.test 
b/sql/test/SQLancer/Tests/sqlancer17.test
--- a/sql/test/SQLancer/Tests/sqlancer17.test
+++ b/sql/test/SQLancer/Tests/sqlancer17.test
@@ -537,3 +537,27 @@ 1
 
 statement ok
 DROP TABLE t3
+
+statement ok
+START TRANSACTION
+
+statement ok
+CREATE TABLE rt0 ("c0" INET, "c1" TINYINT)
+
+statement ok
+CREATE TABLE tz(c1 BLOB)
+
+statement ok
+create or replace view va(vc0) as ((select 4 from tz) union all (select 2 from 
rt0))
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to