-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
Prior to this commit, setting transaction_rows_read_err to a non-zero value would cause a transaction to fail as soon as a statement caused the total number of rows read to exceed transaction_rows_read_err. However, it was possible that each statement could read many more than transaction_rows_read_err rows. This commit adds logic so that a single scan never reads more than transaction_rows_read_err+1 rows if transaction_rows_read_err is set. Informs cockroachdb#70473 Release note (performance improvement): If transaction_rows_read_err is set to a non-zero value, we now ensure that any single scan never reads more than transaction_rows_read_err+1 rows. This prevents transactions that would error due to the transaction_rows_read_err setting from causing a large performance overhead due to large scans.
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
statement ok | ||
CREATE TABLE guardrails (i INT PRIMARY KEY); | ||
INSERT INTO guardrails SELECT generate_series(1, 100) | ||
|
||
# When the transaction_rows_read_err guardrail is set to 1, we apply a limit | ||
# of 2 in all cases except for when we know at most 2 rows are returned. | ||
statement ok | ||
SET transaction_rows_read_err = 1 | ||
|
||
query error txn has read 2 rows, which is above the limit | ||
SELECT * FROM guardrails | ||
|
||
query error txn has read 2 rows, which is above the limit | ||
SELECT * FROM guardrails LIMIT 50 | ||
|
||
statement ok | ||
SELECT * FROM guardrails WHERE i = 1 | ||
|
||
statement error txn has read 2 rows, which is above the limit | ||
SELECT * FROM guardrails WHERE i IN (1, 2) | ||
|
||
query error txn has read 2 rows, which is above the limit | ||
SELECT * FROM guardrails WHERE i > 0 AND i <= 10 | ||
|
||
# When the transaction_rows_read_err guardrail is set to 50, we only apply a | ||
# limit if it's possible that more than 51 rows may be returned. | ||
statement ok | ||
SET transaction_rows_read_err = 50 | ||
|
||
query error txn has read 51 rows, which is above the limit | ||
SELECT * FROM guardrails | ||
|
||
statement ok | ||
SELECT * FROM guardrails LIMIT 50 | ||
|
||
statement ok | ||
SELECT * FROM guardrails WHERE i = 1 | ||
|
||
statement ok | ||
SELECT * FROM guardrails WHERE i > 0 AND i <= 10 | ||
|
||
statement ok | ||
SET transaction_rows_read_err = 150 | ||
|
||
statement ok | ||
CREATE TABLE guardrails2 (i INT PRIMARY KEY); | ||
INSERT INTO guardrails2 SELECT generate_series(1, 150) | ||
|
||
statement ok | ||
BEGIN | ||
|
||
# A full scan shouldn't error if it only scans transaction_rows_read_err rows. | ||
statement ok | ||
SELECT * FROM guardrails2 | ||
|
||
statement ok | ||
COMMIT | ||
|
||
statement ok | ||
BEGIN | ||
|
||
statement ok | ||
SELECT * FROM guardrails | ||
|
||
# The whole transaction has now read more than transaction_rows_read_err rows, | ||
# so error. | ||
query error txn has read 250 rows, which is above the limit | ||
SELECT * FROM guardrails2 | ||
|
||
statement ok | ||
ROLLBACK | ||
|
||
statement ok | ||
RESET transaction_rows_read_err |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# LogicTest: local | ||
|
||
statement ok | ||
CREATE TABLE guardrails (i INT PRIMARY KEY) | ||
|
||
# When the transaction_rows_read_err guardrail is set to 1, we apply a limit | ||
# of 2 in all cases except for when we know at most 2 rows are returned. | ||
statement ok | ||
SET transaction_rows_read_err = 1 | ||
|
||
query T | ||
EXPLAIN (VERBOSE) SELECT * FROM guardrails | ||
---- | ||
distribution: local | ||
vectorized: true | ||
· | ||
• scan | ||
columns: (i) | ||
estimated row count: 1,000 (missing stats) | ||
table: guardrails@guardrails_pkey | ||
spans: LIMITED SCAN | ||
limit: 2 | ||
|
||
query T | ||
EXPLAIN (VERBOSE) SELECT * FROM guardrails LIMIT 50 | ||
---- | ||
distribution: local | ||
vectorized: true | ||
· | ||
• scan | ||
columns: (i) | ||
estimated row count: 50 (missing stats) | ||
table: guardrails@guardrails_pkey | ||
spans: LIMITED SCAN | ||
limit: 2 | ||
|
||
query T | ||
EXPLAIN (VERBOSE) SELECT * FROM guardrails WHERE i = 1 | ||
---- | ||
distribution: local | ||
vectorized: true | ||
· | ||
• scan | ||
columns: (i) | ||
estimated row count: 1 (missing stats) | ||
table: guardrails@guardrails_pkey | ||
spans: /1/0 | ||
|
||
query T | ||
EXPLAIN (VERBOSE) SELECT * FROM guardrails WHERE i IN (1, 2) | ||
---- | ||
distribution: local | ||
vectorized: true | ||
· | ||
• scan | ||
columns: (i) | ||
estimated row count: 2 (missing stats) | ||
table: guardrails@guardrails_pkey | ||
spans: /1-/3 | ||
parallel | ||
|
||
|
||
query T | ||
EXPLAIN (VERBOSE) SELECT * FROM guardrails WHERE i > 0 AND i <= 10 | ||
---- | ||
distribution: local | ||
vectorized: true | ||
· | ||
• scan | ||
columns: (i) | ||
estimated row count: 10 (missing stats) | ||
table: guardrails@guardrails_pkey | ||
spans: /1-/11 | ||
limit: 2 | ||
|
||
# When the transaction_rows_read_err guardrail is set to 50, we only apply a | ||
# limit if it's possible that more than 51 rows may be returned. | ||
statement ok | ||
SET transaction_rows_read_err = 50 | ||
|
||
query T | ||
EXPLAIN (VERBOSE) SELECT * FROM guardrails | ||
---- | ||
distribution: local | ||
vectorized: true | ||
· | ||
• scan | ||
columns: (i) | ||
estimated row count: 1,000 (missing stats) | ||
table: guardrails@guardrails_pkey | ||
spans: LIMITED SCAN | ||
limit: 51 | ||
|
||
query T | ||
EXPLAIN (VERBOSE) SELECT * FROM guardrails LIMIT 50 | ||
---- | ||
distribution: local | ||
vectorized: true | ||
· | ||
• scan | ||
columns: (i) | ||
estimated row count: 50 (missing stats) | ||
table: guardrails@guardrails_pkey | ||
spans: LIMITED SCAN | ||
limit: 50 | ||
|
||
query T | ||
EXPLAIN (VERBOSE) SELECT * FROM guardrails WHERE i = 1 | ||
---- | ||
distribution: local | ||
vectorized: true | ||
· | ||
• scan | ||
columns: (i) | ||
estimated row count: 1 (missing stats) | ||
table: guardrails@guardrails_pkey | ||
spans: /1/0 | ||
|
||
query T | ||
EXPLAIN (VERBOSE) SELECT * FROM guardrails WHERE i > 0 AND i <= 10 | ||
---- | ||
distribution: local | ||
vectorized: true | ||
· | ||
• scan | ||
columns: (i) | ||
estimated row count: 10 (missing stats) | ||
table: guardrails@guardrails_pkey | ||
spans: /1-/11 | ||
parallel | ||
|
||
statement ok | ||
RESET transaction_rows_read_err |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.