Changeset: 9d276b277377 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/9d276b277377
Added Files:
sql/test/BugTracker-2026/Tests/8071-uncommitted-update-delta-scan.test
Modified Files:
sql/storage/bat/bat_storage.c
sql/test/BugTracker-2026/Tests/All
Branch: default
Log Message:
fixed issue 8071, keep update slices aligned
diffs (155 lines):
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
@@ -709,33 +709,61 @@ count_idx(sql_trans *tr, sql_idx *i, int
static BAT *
cs_bind_ubat( column_storage *cs, int access, int type, BUN l, BUN h /* ie max
position < cnt */)
{
- BAT *b;
+ BAT *b, *ids = NULL, *sel = NULL;
assert(access == RD_UPD_ID || access == RD_UPD_VAL);
/* returns the updates for cs */
- if (cs->uibid && cs->uvbid && cs->ucnt) {
- if (access == RD_UPD_ID) {
- if (!(b = temp_descriptor(cs->uibid)))
- return NULL;
- if (!b->tsorted || ((BATtdense2(b) && (b->tseqbase +
BATcount(b)) >= h) ||
- (!BATtdense2(b) && BATcount(b) &&
((oid*)b->theap->base)[BATcount(b)-1] >= h))) {
- BAT *s = BATselect(b, NULL, &l, &h,
true, false, false, false);
- if (!s) {
- bat_destroy(b);
- return NULL;
- }
-
- BAT *nb = BATproject(s, b);
- bat_destroy(s);
- bat_destroy(b);
- b = nb;
- }
+ if (!(cs->uibid && cs->uvbid && cs->ucnt))
+ return e_BAT(access == RD_UPD_ID ? TYPE_oid : type);
+
+ if (!(ids = temp_descriptor(cs->uibid)))
+ return NULL;
+ /* Slice the update ids when they extend beyond this segment. The
+ * update values must use exactly the same selection, otherwise the
+ * id/value BATs passed to sql.delta have different sizes. Both the
+ * lower and upper bound matter: a segment can start above all ids
+ * even though its end is beyond them. */
+ bool need_slice = !ids->tsorted;
+ if (!need_slice && BATcount(ids)) {
+ oid first, last;
+ if (BATtdense2(ids)) {
+ first = ids->tseqbase;
+ last = ids->tseqbase + BATcount(ids) - 1;
} else {
- b = temp_descriptor(cs->uvbid);
+ first = ((oid*)ids->theap->base)[0];
+ last = ((oid*)ids->theap->base)[BATcount(ids)-1];
+ }
+ need_slice = first < l || (h != BUN_NONE && last >= h);
+ }
+ if (need_slice) {
+ sel = BATselect(ids, NULL, &l, &h, true, false, false, false);
+ if (!sel) {
+ bat_destroy(ids);
+ return NULL;
+ }
+ }
+
+ if (access == RD_UPD_ID) {
+ if (sel) {
+ b = BATproject(sel, ids);
+ } else {
+ b = ids;
+ ids = NULL;
}
} else {
- b = e_BAT(access == RD_UPD_ID?TYPE_oid:type);
- }
+ if (!(b = temp_descriptor(cs->uvbid))) {
+ bat_destroy(sel);
+ bat_destroy(ids);
+ return NULL;
+ }
+ if (sel) {
+ BAT *nb = BATproject(sel, b);
+ bat_destroy(b);
+ b = nb;
+ }
+ }
+ bat_destroy(sel);
+ bat_destroy(ids);
return b;
}
diff --git
a/sql/test/BugTracker-2026/Tests/8071-uncommitted-update-delta-scan.test
b/sql/test/BugTracker-2026/Tests/8071-uncommitted-update-delta-scan.test
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2026/Tests/8071-uncommitted-update-delta-scan.test
@@ -0,0 +1,56 @@
+statement ok
+DROP TABLE IF EXISTS t
+
+statement ok
+CREATE TABLE t(id INT PRIMARY KEY, v BIGINT)
+
+statement ok rowcount 300000
+INSERT INTO t
+SELECT value AS generated_id, CAST(value AS BIGINT) AS generated_v
+FROM sys.generate_series(0, 300000)
+
+statement ok
+START TRANSACTION
+
+statement ok
+UPDATE t
+SET v = v + 100000
+WHERE id IN (10, 1100, 2100, 10100, 100100, 200100, 299100)
+
+query TIII
+SELECT CASE
+ WHEN COUNT(*) = 300000
+ AND SUM(v) = 45000550000
+ AND SUM(CASE WHEN id IN (10, 1100, 2100, 10100, 100100, 200100,
299100)
+ AND v = id + 100000
+ THEN 1 ELSE 0 END) = 7
+ THEN 'PASS' ELSE 'FAIL'
+ END AS oracle,
+ COUNT(*) AS row_count,
+ SUM(v) AS value_sum,
+ SUM(CASE WHEN id IN (10, 1100, 2100, 10100, 100100, 200100, 299100)
+ AND v = id + 100000
+ THEN 1 ELSE 0 END) AS correct_updated_rows
+FROM t
+----
+PASS 300000 45000550000 7
+
+query II nosort
+SELECT id, v
+FROM t
+WHERE id IN (10, 1100, 2100, 10100, 100100, 200100, 299100)
+ORDER BY id
+----
+10 100010
+1100 101100
+2100 102100
+10100 110100
+100100 200100
+200100 300100
+299100 399100
+
+statement ok
+ROLLBACK
+
+statement ok
+DROP TABLE t
diff --git a/sql/test/BugTracker-2026/Tests/All
b/sql/test/BugTracker-2026/Tests/All
--- a/sql/test/BugTracker-2026/Tests/All
+++ b/sql/test/BugTracker-2026/Tests/All
@@ -229,3 +229,4 @@ KNOWNFAIL?8030-inner-join-group-by-bug
8067-duplicate-in-values
8068-pipeline-limit-slice-join
8070-sum-constant-drops-groupby-aggregates
+8071-uncommitted-update-delta-scan
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]