-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
RYOW for DuckDB within an explicit txn #5376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
drrtuy
wants to merge
2
commits into
MariaDB:11.4
Choose a base branch
from
drrtuy:bb-11.4-txn-ryow-scan
base: 11.4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
storage/duckdb/mysql-test/duckdb/r/cross_engine_ryow.result
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # | ||
| # Cross-engine RYOW: duckdb_cross_engine_ryow toggles visibility of | ||
| # uncommitted parent-transaction writes to non-DuckDB tables | ||
| # | ||
| DROP DATABASE IF EXISTS cross_engine_ryow; | ||
| CREATE DATABASE cross_engine_ryow CHARACTER SET utf8mb4; | ||
| USE cross_engine_ryow; | ||
| CREATE TABLE t_duck (id INT PRIMARY KEY, val VARCHAR(50)) ENGINE=DuckDB; | ||
| CREATE TABLE t_inno (id INT PRIMARY KEY, name VARCHAR(50), score INT) ENGINE=InnoDB; | ||
| INSERT INTO t_duck VALUES (1,'alpha'),(2,'beta'),(3,'gamma'),(4,'delta'),(5,'epsilon'),(6,'zeta'); | ||
| INSERT INTO t_inno VALUES (1,'Alice',90),(2,'Bob',80),(3,'Carol',70),(4,'Dave',60),(5,'Eve',50); | ||
|
|
||
| # (1) RYOW disabled (default): uncommitted writes are NOT visible | ||
|
|
||
| SET SESSION duckdb_cross_engine_ryow=0; | ||
| BEGIN; | ||
| UPDATE t_inno SET score=999 WHERE id=2; | ||
| INSERT INTO t_inno VALUES (6,'Frank',100); | ||
| SELECT d.id, i.name, i.score FROM t_duck d JOIN t_inno i ON d.id=i.id; | ||
| id name score | ||
| 1 Alice 90 | ||
| 2 Bob 80 | ||
| 3 Carol 70 | ||
| 4 Dave 60 | ||
| 5 Eve 50 | ||
| ROLLBACK; | ||
|
|
||
| # (2) RYOW enabled: uncommitted writes ARE visible (read own writes) | ||
|
|
||
| SET SESSION duckdb_cross_engine_ryow=1; | ||
| BEGIN; | ||
| UPDATE t_inno SET score=999 WHERE id=2; | ||
| INSERT INTO t_inno VALUES (6,'Frank',100); | ||
| SELECT d.id, i.name, i.score FROM t_duck d JOIN t_inno i ON d.id=i.id; | ||
| id name score | ||
| 1 Alice 90 | ||
| 2 Bob 999 | ||
| 3 Carol 70 | ||
| 4 Dave 60 | ||
| 5 Eve 50 | ||
| 6 Frank 100 | ||
| ROLLBACK; | ||
|
|
||
| # (3) After rollback, committed state is intact | ||
|
|
||
| SELECT d.id, i.name, i.score FROM t_duck d JOIN t_inno i ON d.id=i.id; | ||
| id name score | ||
| 1 Alice 90 | ||
| 2 Bob 80 | ||
| 3 Carol 70 | ||
| 4 Dave 60 | ||
| 5 Eve 50 | ||
|
|
||
| # (4) RYOW enabled + large external table (rows > DuckDB vector size): | ||
| # the direct handler scan spans multiple chunks and must still expose | ||
| # the parent transaction's uncommitted write on re-read. | ||
|
|
||
| CREATE TABLE t_inno_big (id INT PRIMARY KEY, score INT) ENGINE=InnoDB; | ||
| INSERT INTO t_inno_big SELECT seq, seq FROM seq_1_to_3000; | ||
| SET SESSION duckdb_cross_engine_ryow=1; | ||
| BEGIN; | ||
| UPDATE t_inno_big SET score=999 WHERE id=1; | ||
| SELECT i.score FROM t_duck d JOIN t_inno_big i ON d.id=i.id WHERE i.id=1; | ||
| score | ||
| 999 | ||
| ROLLBACK; | ||
| DROP TABLE t_inno_big; | ||
|
|
||
| # Cleanup | ||
|
|
||
| SET SESSION duckdb_cross_engine_ryow=DEFAULT; | ||
| DROP TABLE t_duck; | ||
| DROP TABLE t_inno; | ||
| DROP DATABASE cross_engine_ryow; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| --source include/have_sequence.inc | ||
|
|
||
| --echo # | ||
| --echo # Cross-engine RYOW: duckdb_cross_engine_ryow toggles visibility of | ||
| --echo # uncommitted parent-transaction writes to non-DuckDB tables | ||
| --echo # | ||
|
|
||
| --disable_warnings | ||
| DROP DATABASE IF EXISTS cross_engine_ryow; | ||
| --enable_warnings | ||
| CREATE DATABASE cross_engine_ryow CHARACTER SET utf8mb4; | ||
| USE cross_engine_ryow; | ||
| CREATE TABLE t_duck (id INT PRIMARY KEY, val VARCHAR(50)) ENGINE=DuckDB; | ||
| CREATE TABLE t_inno (id INT PRIMARY KEY, name VARCHAR(50), score INT) ENGINE=InnoDB; | ||
| INSERT INTO t_duck VALUES (1,'alpha'),(2,'beta'),(3,'gamma'),(4,'delta'),(5,'epsilon'),(6,'zeta'); | ||
| INSERT INTO t_inno VALUES (1,'Alice',90),(2,'Bob',80),(3,'Carol',70),(4,'Dave',60),(5,'Eve',50); | ||
|
|
||
| --echo | ||
| --echo # (1) RYOW disabled (default): uncommitted writes are NOT visible | ||
| --echo | ||
| SET SESSION duckdb_cross_engine_ryow=0; | ||
| BEGIN; | ||
| UPDATE t_inno SET score=999 WHERE id=2; | ||
| INSERT INTO t_inno VALUES (6,'Frank',100); | ||
| --sorted_result | ||
| SELECT d.id, i.name, i.score FROM t_duck d JOIN t_inno i ON d.id=i.id; | ||
| ROLLBACK; | ||
|
|
||
| --echo | ||
| --echo # (2) RYOW enabled: uncommitted writes ARE visible (read own writes) | ||
| --echo | ||
| SET SESSION duckdb_cross_engine_ryow=1; | ||
| BEGIN; | ||
| UPDATE t_inno SET score=999 WHERE id=2; | ||
| INSERT INTO t_inno VALUES (6,'Frank',100); | ||
| --sorted_result | ||
| SELECT d.id, i.name, i.score FROM t_duck d JOIN t_inno i ON d.id=i.id; | ||
| ROLLBACK; | ||
|
|
||
| --echo | ||
| --echo # (3) After rollback, committed state is intact | ||
| --echo | ||
| --sorted_result | ||
| SELECT d.id, i.name, i.score FROM t_duck d JOIN t_inno i ON d.id=i.id; | ||
|
|
||
| --echo | ||
| --echo # (4) RYOW enabled + large external table (rows > DuckDB vector size): | ||
| --echo # the direct handler scan spans multiple chunks and must still expose | ||
| --echo # the parent transaction's uncommitted write on re-read. | ||
| --echo | ||
| CREATE TABLE t_inno_big (id INT PRIMARY KEY, score INT) ENGINE=InnoDB; | ||
| INSERT INTO t_inno_big SELECT seq, seq FROM seq_1_to_3000; | ||
| SET SESSION duckdb_cross_engine_ryow=1; | ||
| BEGIN; | ||
| UPDATE t_inno_big SET score=999 WHERE id=1; | ||
| SELECT i.score FROM t_duck d JOIN t_inno_big i ON d.id=i.id WHERE i.id=1; | ||
| ROLLBACK; | ||
| DROP TABLE t_inno_big; | ||
|
|
||
| --echo | ||
| --echo # Cleanup | ||
| --echo | ||
| SET SESSION duckdb_cross_engine_ryow=DEFAULT; | ||
| DROP TABLE t_duck; | ||
| DROP TABLE t_inno; | ||
| DROP DATABASE cross_engine_ryow; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
state.directis true, the scan bypasses the fiber-based execution and runs directly. However, DuckDB may execute the table function on one of its worker threads rather than the main connection thread.Because MariaDB storage engines (like InnoDB) rely heavily on the thread-local
current_thdbeing set to the correctTHDduring handler operations (such asha_rnd_next), calling these methods on a DuckDB worker thread wherecurrent_thdisNULLor incorrect will lead to undefined behavior, assertion failures, or server crashes.To prevent this, we should temporarily set/swap
current_thdtotbl->in_use(and restore it afterwards) during the direct handler scan execution if it is running on a different thread, or ensure that the execution of_mdb_scan_directis strictly confined to the connection thread.