Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
37791: sql: use a CockroachDB-specific error code for schg errs upon COMMIT r=knz a=knz This patch changes the error reported upon schema change failures raised at COMMIT (multi-stmt txns) to a new CockroachDB-specific code called "transaction committed with schema change failure", XXA00. Previously, this situation used the extant PostgreSQL error code "40003", "statement completion unknown", however that was misleading: the situation is actually pretty clear and the statement is actually known to have completed. The other situation where CockroachDB produces "completion unknown" is when KV fails to receive an acknowledgement for the txn commit. Compare: | Actual transaction status | Does the gateway know? | Error code reported to client | |------------------------------------------------|------------------------|----------------------------------------------------| | EITHER fully committed OR fully aborted | no | "completion unknown" | | BOTH partially committed AND partially aborted | yes | "transaction committed with schema change failure" | Using a separate error code ensures the situation is more noticeable and can be documented separately. After this patch: ``` root@127.0.0.1:19343/defaultdb> create table t(x int); insert into t(x) values (0); INSERT 1 root@127.0.0.1:19343/defaultdb> begin; > alter table t add column z int default 123; > insert into t(x) values (1); > alter table t add column y float as (1::float / x::float) stored; > commit; pq: transaction committed but schema change aborted with error: division by zero HINT: Some of the non-DDL statements may have committed successfully, but some of the DDL statement(s) failed. Manual inspection may be required to determine the actual state of the database. ``` (in this specific example, the ALTER failed but the INSERT was committed. There are two rows in the table.) Some context for the reader not familiar with this situation (I had to reverse engineer the code to understand this, so I may as well write this down here for posterity): in CockroachDB, a processing error raised during the post-commit processing of schema changes is "interesting" in that it really violates the "A" in ACID. At that point: - all the non-DDL effects of the txns are successfully committed (and cannot be rolled back any more); - some the DDL up to the one that triggered the error may be committed (author note: I am unsure -- not investigating that); - the last DDL that caused the error was aborted. In effect, the transaction is both committed and aborted at the same time. Release note (sql change): CockroachDB now reports a dedicated SQL error code in the particular situation where a multi-statement transaction is COMMITTed but one of the schema change (DDL) operations failed. As in previous versions, CockroachDB leaves the transaction partly committed and partly aborted in that case; the new error code aims to facilitate the recognition of this case in client code. 37914: opt: add PushSelectIntoWindow r=justinj a=justinj This commit adds a rule to push select filters into a Window expression. This is valid to do whenever a filter is bound by the partition columns of the Window expression. Release note: None Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com> Co-authored-by: Justin Jaffray <justin@cockroachlabs.com>
- Loading branch information
Showing
9 changed files
with
358 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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 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 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,38 @@ | ||
# LogicTest: local local-opt fakedist fakedist-metadata fakedist-opt | ||
|
||
# This test exercises the presence of an explanatory hint when a transaction | ||
# ends up partially committed and partially aborted. | ||
|
||
statement ok | ||
CREATE TABLE t (x INT); INSERT INTO t (x) VALUES (0); | ||
|
||
statement ok | ||
BEGIN | ||
|
||
statement ok | ||
ALTER TABLE t ADD COLUMN z INT DEFAULT 123 | ||
|
||
statement ok | ||
INSERT INTO t (x) VALUES (1) | ||
|
||
statement ok | ||
ALTER TABLE t ADD COLUMN y FLOAT AS (1::FLOAT / x::FLOAT) STORED | ||
|
||
statement error pgcode XXA00 division by zero.*\nHINT:.*\nManual inspection may be required | ||
COMMIT | ||
|
||
# Verify that the txn was indeed partially committed: the INSERT succeeded. | ||
query I rowsort | ||
SELECT * FROM t | ||
---- | ||
0 | ||
1 | ||
|
||
# Verify that the txn was indeed partially aborted: the first ALTER failed. | ||
query TT | ||
SHOW CREATE t | ||
---- | ||
t CREATE TABLE t ( | ||
x INT8 NULL, | ||
FAMILY "primary" (x, rowid) | ||
) |
This file contains 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 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 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 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.