Skip to content
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

[YSQL] serializable isolation SELECT from table should conflict with DDL on table #5602

Closed
jaki opened this issue Sep 5, 2020 · 2 comments
Closed
Assignees
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue

Comments

@jaki
Copy link
Contributor

jaki commented Sep 5, 2020

Jira Link: DB-2293
Serializability is violated for certain cases where SELECTs on tables should have noticed conflicts with DDLs on the same tables.

Here is example 1:

session A session B output (PG) output (YB)
CREATE TABLE a (i int)
CREATE TABLE b (i int)
BEGIN ISOLATION LEVEL SERIALIZABLE
SELECT * FROM a 0 rows 0 rows
DROP TABLE a (waits until commit) (succeeds immediately)
INSERT INTO b VALUES (1)
SELECT * FROM b N/A 1 row
COMMIT

It is not serializable, yet it commits successfully for YB. The txn is not serializable because

  • it could not have happened before INSERT INTO b since SELECT * FROM b returns the row
  • it could not have happened after INSERT INTO b since SELECT * FROM a does not error when it should have if we executed it after the DROP TABLE a

Maybe we can lump this under transactional DDL issues, but there's a second more concerning example 2:

session A session B output (PG) output (YB)
CREATE TABLE a (i int)
CREATE INDEX ON a (i ASC)
CREATE TABLE b (i int)
BEGIN ISOLATION LEVEL SERIALIZABLE
SELECT * FROM a ORDER BY i 0 rows 0 rows
DROP INDEX a_i_idx (waits until commit) (succeeds immediately)
INSERT INTO a VALUES (1)
INSERT INTO b VALUES (1)
SELECT * FROM b N/A 1 row
COMMIT

It is not serializable, yet it commits successfully for YB. The txn is not serializable because

  • it could not have happened before INSERT INTO b since SELECT * FROM b returns the row
  • it could not have happened after INSERT INTO b since SELECT * FROM a returns no rows when it should have returned the row from INSERT INTO a

These issues seem related to not locking tables properly. A similar example is easy to come up with for TRUNCATE. I believe we do write weak intents for the table when we SELECT from the table in the txn, but we might not be finding the conflicts properly. Maybe these issues are all just part of transactional DDL (#3109).

@jaki jaki added kind/bug This issue is a bug area/ysql Yugabyte SQL (YSQL) labels Sep 5, 2020
@jaki
Copy link
Contributor Author

jaki commented Apr 27, 2021

These issues have been fixed by causing catalog version mismatch on SELECT * FROM b. However, we will now go back to the old way when D9983 lands (and related D10666). This issue will likely resurface.

@tverona1
Copy link
Contributor

Resolving this as fix: In both scenarios above, the drop table DDL aborts the DML transaction.

@tverona1 tverona1 moved this to Done in YQL-beta Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue
Projects
Status: Done
Development

No branches or pull requests

4 participants