Changeset: 569e990addc1 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/569e990addc1
Modified Files:
gdk/gdk_batop.c
gdk/gdk_heap.c
sql/server/rel_select.c
sql/storage/bat/bat_storage.c
sql/storage/store.c
sql/test/BugTracker-2022/Tests/All
sql/test/miscellaneous/Tests/simple_selects.test
Branch: default
Log Message:
Merged with Jan2022
diffs (truncated from 442 to 300 lines):
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -349,8 +349,6 @@ append_varsized_bat(BAT *b, BATiter *ni,
/* if b is still empty, in the transient farm, and n
* is read-only, we replace b's vheap with a reference
* to n's */
- /* make sure locking happens in a predictable order:
- * lowest id first */
MT_lock_set(&b->theaplock);
if (b->tvheap->parentid != b->batCacheid)
BBPunshare(b->tvheap->parentid);
@@ -417,6 +415,30 @@ append_varsized_bat(BAT *b, BATiter *ni,
MT_lock_unset(&b->theaplock);
HEAPdecref(oh, false);
}
+ if (BATcount(b) == 0 && BATatoms[b->ttype].atomFix == NULL &&
+ ci->tpe == cand_dense && ci->ncand == ni->count) {
+ /* just copy the heaps */
+ if (HEAPgrow(&b->theaplock, &b->tvheap, ni->vhfree, false) !=
GDK_SUCCEED)
+ return GDK_FAIL;
+ memcpy(b->theap->base, ni->base, ni->hfree);
+ memcpy(b->tvheap->base, ni->vh->base, ni->vhfree);
+ b->theap->free = ni->hfree;
+ b->tvheap->free = ni->vhfree;
+ BATsetcount(b, ni->count);
+ b->tnil = ni->nil;
+ b->tnonil = ni->nonil;
+ b->tsorted = ni->sorted;
+ b->tnosorted = ni->b->tnosorted;
+ b->trevsorted = ni->revsorted;
+ b->tnorevsorted = ni->b->tnorevsorted;
+ b->tkey = ni->key;
+ b->tnokey[0] = ni->b->tnokey[0];
+ b->tnokey[1] = ni->b->tnokey[1];
+ b->tminpos = ni->minpos;
+ b->tmaxpos = ni->maxpos;
+ b->tunique_est = ni->unique_est;
+ return GDK_SUCCEED;
+ }
/* copy data from n to b */
r = BATcount(b);
MT_rwlock_wrlock(&b->thashlock);
diff --git a/gdk/gdk_heap.c b/gdk/gdk_heap.c
--- a/gdk/gdk_heap.c
+++ b/gdk/gdk_heap.c
@@ -1098,7 +1098,11 @@ HEAP_malloc(BAT *b, size_t nbytes)
size_t newsize;
assert(heap->free + MAX(heap->free, nbytes) <= VAR_MAX);
+#if SIZEOF_SIZE_T == 4
newsize = MIN(heap->free, (size_t) 1 << 20);
+#else
+ newsize = MIN(heap->free, (size_t) 1 << 30);
+#endif
newsize = (size_t) roundup_8(heap->free + MAX(newsize, nbytes));
assert(heap->free <= VAR_MAX);
block = (size_t) heap->free; /* current end-of-heap */
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
@@ -1141,9 +1141,14 @@ rel_column_ref(sql_query *query, sql_rel
if (!exp && inner)
if (!(exp = rel_bind_column(sql, inner, name, f, 0)) &&
sql->session->status == -ERR_AMBIGUOUS)
return NULL;
- if (!exp && inner && is_sql_aggr(f) && is_groupby(inner->op))
- if (!(exp = rel_bind_column(sql, inner->l, name, f, 0))
&& sql->session->status == -ERR_AMBIGUOUS)
+ if (!exp && inner && is_sql_aggr(f) && (is_groupby(inner->op)
|| is_select(inner->op))) {
+ /* if inner is selection, ie having clause, get the
left relation to reach group by */
+ sql_rel *gp = inner;
+ while (gp && is_select(gp->op))
+ gp = gp->l;
+ if (gp && gp->l && !(exp = rel_bind_column(sql, gp->l,
name, f, 0)) && sql->session->status == -ERR_AMBIGUOUS)
return NULL;
+ }
if (!exp && query && query_has_outer(query)) {
int i;
@@ -1226,9 +1231,14 @@ rel_column_ref(sql_query *query, sql_rel
if (!exp && rel && inner)
if (!(exp = rel_bind_column2(sql, inner, tname, cname,
f)) && sql->session->status == -ERR_AMBIGUOUS)
return NULL;
- if (!exp && inner && is_sql_aggr(f) && is_groupby(inner->op))
- if (!(exp = rel_bind_column2(sql, inner->l, tname,
cname, f)) && sql->session->status == -ERR_AMBIGUOUS)
+ if (!exp && inner && is_sql_aggr(f) && (is_groupby(inner->op)
|| is_select(inner->op))) {
+ /* if inner is selection, ie having clause, get the
left relation to reach group by */
+ sql_rel *gp = inner;
+ while (gp && is_select(gp->op))
+ gp = gp->l;
+ if (gp && gp->l && !(exp = rel_bind_column2(sql, gp->l,
tname, cname, f)) && sql->session->status == -ERR_AMBIGUOUS)
return NULL;
+ }
if (!exp && query && query_has_outer(query)) {
int i;
diff --git a/sql/storage/bat/bat_storage.c b/sql/storage/bat/bat_storage.c
--- a/sql/storage/bat/bat_storage.c
+++ b/sql/storage/bat/bat_storage.c
@@ -2937,7 +2937,7 @@ create_col(sql_trans *tr, sql_column *c)
/* alter ? */
if (ol_first_node(c->t->columns) && (fc =
ol_first_node(c->t->columns)->data) != NULL) {
- storage *s = ATOMIC_PTR_GET(&fc->t->data);
+ storage *s = tab_timestamp_storage(tr, fc->t);
cnt = segs_end(s->segs, tr, c->t);
}
if (cnt && fc != c) {
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -3031,9 +3031,8 @@ part_dup(sql_trans *tr, sql_part *op, sq
list_append(p->part.values, nextv);
}
}
- if ((res = os_add(mt->s->parts, tr, p->base.name, dup_base(&p->base))))
{
- return res;
- }
+ if (isGlobal(mt) && (res = os_add(mt->s->parts, tr, p->base.name,
dup_base(&p->base))))
+ return res;
*pres = p;
return res;
}
@@ -3066,9 +3065,8 @@ trigger_dup(sql_trans *tr, sql_trigger *
list_append(nt->columns, kc_dup(tr, okc, t));
}
- if (isGlobal(t) && (res = os_add(t->s->triggers, tr, nt->base.name,
dup_base(&nt->base)))) {
- return res;
- }
+ if (isGlobal(t) && (res = os_add(t->s->triggers, tr, nt->base.name,
dup_base(&nt->base))))
+ return res;
*tres = nt;
return res;
}
@@ -3402,7 +3400,7 @@ sql_trans_copy_idx( sql_trans *tr, sql_t
if ((res = ol_add(t->idxs, &ni->base)))
return res;
- if ((res = os_add(t->s->idxs, tr, ni->base.name, dup_base(&ni->base))))
+ if (isGlobal(t) && (res = os_add(t->s->idxs, tr, ni->base.name,
dup_base(&ni->base))))
return res;
if ((res = store_reset_sql_functions(tr, t->base.id))) /* reset sql
functions depending on the table */
return res;
@@ -3473,7 +3471,7 @@ sql_trans_copy_trigger( sql_trans *tr, s
if ((res = ol_add(t->triggers, &nt->base)))
return res;
- if ((res = os_add(t->s->triggers, tr, nt->base.name,
dup_base(&nt->base))))
+ if (isGlobal(t) && (res = os_add(t->s->triggers, tr, nt->base.name,
dup_base(&nt->base))))
return res;
if ((res = store_reset_sql_functions(tr, t->base.id))) /* reset sql
functions depending on the table */
return res;
@@ -4249,7 +4247,7 @@ sys_drop_idx(sql_trans *tr, sql_idx * i,
return res;
}
- /* remove idx from schema and table*/
+ /* remove idx from schema and table */
if (isGlobal(i->t))
if ((res = os_del(i->t->s->idxs, tr, i->base.name,
dup_base(&i->base))))
return res;
@@ -6546,9 +6544,8 @@ sql_trans_drop_key(sql_trans *tr, sql_sc
if (drop_action == DROP_CASCADE_START || drop_action == DROP_CASCADE) {
sqlid *local_id = MNEW(sqlid);
- if (!local_id) {
+ if (!local_id)
return -1;
- }
if (!tr->dropped) {
tr->dropped = list_create((fdestroy) &id_destroy);
@@ -6566,7 +6563,7 @@ sql_trans_drop_key(sql_trans *tr, sql_sc
if ((res = store_reset_sql_functions(tr, t->base.id))) /* reset sql
functions depending on the table */
return res;
- if (!isTempTable(k->t) && (res = sys_drop_key(tr, k, drop_action)))
+ if ((res = sys_drop_key(tr, k, drop_action)))
return res;
/*Clean the key from the keys*/
@@ -6656,9 +6653,8 @@ sql_trans_drop_idx(sql_trans *tr, sql_sc
if (drop_action == DROP_CASCADE_START || drop_action == DROP_CASCADE) {
sqlid *local_id = MNEW(sqlid);
- if (!local_id) {
+ if (!local_id)
return -1;
- }
if (!tr->dropped) {
tr->dropped = list_create((fdestroy) &id_destroy);
@@ -6671,7 +6667,7 @@ sql_trans_drop_idx(sql_trans *tr, sql_sc
list_append(tr->dropped, local_id);
}
- if (!isTempTable(i->t) && (res = sys_drop_idx(tr, i, drop_action)))
+ if ((res = sys_drop_idx(tr, i, drop_action)))
return res;
if ((res = store_reset_sql_functions(tr, i->t->base.id))) /* reset sql
functions depending on the table */
return res;
diff --git a/sql/test/BugTracker-2022/Tests/All
b/sql/test/BugTracker-2022/Tests/All
--- a/sql/test/BugTracker-2022/Tests/All
+++ b/sql/test/BugTracker-2022/Tests/All
@@ -6,3 +6,4 @@ HAVE_LIBPY3?python-udf-inside-udf.Bug-72
empty-MAL.Bug-7259
pkey-restart.Bug-7263
delete-update.Bug-7267
+having-clauses.Bug-7278
diff --git a/sql/test/BugTracker-2022/Tests/having-clauses.Bug-7278.test
b/sql/test/BugTracker-2022/Tests/having-clauses.Bug-7278.test
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2022/Tests/having-clauses.Bug-7278.test
@@ -0,0 +1,176 @@
+statement ok
+START TRANSACTION
+
+statement ok
+create table x (x int, y int, z int)
+
+statement ok rowcount 3
+insert into x values (1,1,1),(2,2,2),(3,3,3)
+
+query I rowsort
+select y from x group by y having count(z) > 1 and count(x) > 1
+----
+
+query I nosort
+select y from x group by y order by count(z) > 1 and count(x) > 1
+----
+1
+2
+3
+
+query I nosort
+select y from x group by y order by count(z), count(x)
+----
+1
+2
+3
+
+query I nosort
+select y from x group by y having count(z) > 1 and count(x) > 1 order by
count(z), count(x)
+----
+
+query I nosort
+select y from x group by y having count(z) > 1 and count(x) > 1 order by
count(z) > 1 and count(x) > 1
+----
+
+query I rowsort
+select count(y) from x group by y having count(z) > 1 and count(x) > 1
+----
+
+query I nosort
+select count(y) from x group by y order by count(z) > 1 and count(x) > 1
+----
+1
+1
+1
+
+query I nosort
+select count(y) from x group by y order by count(z), count(x)
+----
+1
+1
+1
+
+query I nosort
+select count(y) from x group by y having count(z) > 1 and count(x) > 1 order
by count(z), count(x)
+----
+
+query I nosort
+select count(y) from x group by y having count(z) > 1 and count(x) > 1 order
by count(z) > 1 and count(x) > 1
+----
+
+query I rowsort
+select count(x) from x group by y having count(z) > 1 and count(x) > 1
+----
+
+query II nosort
+select count(x), count(z) from x group by y order by count(z) > 1 and count(x)
> 1
+----
+1
+1
+1
+1
+1
+1
+
+query II nosort
+select count(x), count(z) from x group by y order by count(z), count(x)
+----
+1
+1
+1
+1
+1
+1
+
+query II nosort
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]