dolthub / dolthub/dolt

Using trigger to update table with multiple inserts is off by one.

Open
#4,495 0 comments 0 reactions 1 assignee Claimed by @zachmu View on GitHub
bug correctness good repro sql
Dominant language
Go
Stars
24.4k
Forks
873
Avg merge
1d 5h
Merged PRs (30d)
108

Description

Steps to reproduce:
```
tmp_db> create table mytbl (i int);
tmp_db> create table seqtbl (x int);
tmp_db> insert into seqtbl values (1000);
Query OK, 1 row affected
tmp_db> create trigger trig before insert on mytbl for each row begin update seqtbl set x = (select count(i) from mytbl); end;
tmp_db> insert into mytbl values (1), (2), (3), (4), (5);
Query OK, 5 rows affected
tmp_db> select * from mytbl;
+---+
| i |
+---+
| 2 |
| 5 |
| 3 |
| 1 |
| 4 |
+---+
tmp_db> select * from seqtbl;
+---+
| x |
+---+
| 3 |
+---+
```
seqtbl should have 4 instead of 3.

When stepping through this issue, the first insert updates seqtbl correctly, but from the second one onwards, they are all one behind the correct value.
Shouldn't be an issue with caching, as this was discovered after fix that disables subquerying for trigger blocks.
I think it has something to do with not flushing enough.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.