Changeset: 086054b9400a for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/086054b9400a Modified Files: gdk/gdk_bat.c gdk/gdk_bbp.c sql/backends/monet5/rel_bin.c Branch: default Log Message:
Merge with Dec2023 branch. diffs (103 lines): diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c --- a/gdk/gdk_bat.c +++ b/gdk/gdk_bat.c @@ -2550,6 +2550,7 @@ BATmode(BAT *b, bool transient) BATiter bi = bat_iterator(b); bool mustrelease = false; + bool mustretain = false; bat bid = b->batCacheid; if (transient != bi.transient) { @@ -2564,16 +2565,20 @@ BATmode(BAT *b, bool transient) } } - /* persistent BATs get a logical reference */ + /* we need to delay the calls to BBPretain and + * BBPrelease until after we have released our reference + * to the heaps (i.e. until after bat_iterator_end), + * because in either case, BBPfree can be called (either + * directly here or in BBPtrim) which waits for the heap + * reference to come down. BBPretain calls incref which + * waits until the trim that is waiting for us is done, + * so that causes deadlock, and BBPrelease can call + * BBPfree which causes deadlock with a single thread */ if (!transient) { - BBPretain(bid); + /* persistent BATs get a logical reference */ + mustretain = true; } else if (!bi.transient) { - /* we need to delay the release because if there - * is no fix and the bat is loaded, BBPrelease - * can call BBPfree which calls BATfree which - * may hang while waiting for the heap reference - * that we have because of the BAT iterator to - * come down, in other words, deadlock */ + /* transient BATs loose their logical reference */ mustrelease = true; } MT_lock_set(&GDKswapLock(bid)); @@ -2605,8 +2610,10 @@ BATmode(BAT *b, bool transient) MT_lock_unset(&GDKswapLock(bid)); } bat_iterator_end(&bi); - /* release after bat_iterator_end because of refs to heaps */ - if (mustrelease) + /* retain/release after bat_iterator_end because of refs to heaps */ + if (mustretain) + BBPretain(bid); + else if (mustrelease) BBPrelease(bid); return GDK_SUCCEED; } diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c --- a/gdk/gdk_bbp.c +++ b/gdk/gdk_bbp.c @@ -4073,6 +4073,7 @@ BBPsync(int cnt, bat *restrict subcommit /* move any tail/theap files we find for this bat that * are in the BACKUP directory to the SUBCOMMIT * directory */ + assert(b->ttype > 0); /* no unknown types allowed */ char fname[16]; /* plenty big enough */ if (snprintf(fname, sizeof(fname), "%o", (unsigned) bid) < 16) { /* the snprintf never fails, any of the 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 @@ -6661,7 +6661,15 @@ static stmt * rel2bin_merge(backend *be, sql_rel *rel, list *refs) { mvc *sql = be->mvc; - sql_rel *join = rel->l, *r = rel->r; + sql_rel *join; + + if (is_project(((sql_rel*)rel->l)->op)) { + join = ((sql_rel*)rel->l)->l; + } else { + join = rel->l; + } + + sql_rel *r = rel->r; stmt *join_st, *bt_stmt, *target_stmt, *jl, *jr, *ld, *rd = NULL, *ns; list *slist = sa_list(sql->sa); diff --git a/sql/test/BugTracker-2024/Tests/merge-into-gh-7503.test b/sql/test/BugTracker-2024/Tests/merge-into-gh-7503.test new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2024/Tests/merge-into-gh-7503.test @@ -0,0 +1,14 @@ +statement ok +CREATE TABLE logs(id int, activity varchar(255) NOT NULL) + +statement ok +CREATE TABLE stats(activity varchar(255) NOT NULL, absolute_reworks int) + +statement ok +WITH rework_stats AS (SELECT activity, count(*) AS frequency FROM (SELECT activity, count(*) AS reworks FROM logs GROUP BY activity HAVING count(*) > 1) AS case_reworks GROUP BY activity) MERGE INTO stats USING rework_stats on rework_stats.activity = stats.activity WHEN MATCHED THEN UPDATE SET absolute_reworks = rework_stats.frequency + +statement ok +DROP TABLE logs + +statement ok +DROP TABLE stats _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org