Skip to content

sql: make table PUBLIC when references created in transaction#25786

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
vivekmenezes:checktxn
May 22, 2018
Merged

sql: make table PUBLIC when references created in transaction#25786
craig[bot] merged 1 commit intocockroachdb:masterfrom
vivekmenezes:checktxn

Conversation

@vivekmenezes
Copy link
Copy Markdown
Contributor

Normally a table with references (FK, interleaved) is
placed in the ADD state to allow the referenced tables
to be upgraded with backreferences across the cluster,
before the cluster sees the ADD table in the PUBLIC state.
When all the table references are created in the same
transaction the table can be made PUBLIC immediately
because all the references are still not visible to
the cluster. This is particularly valuable when commands
within a transaction need to use the PUBLIC table and
will normally barf on seeing a table in the ADD state.

This also fixes a problem with column backfill in the
presence of FKs.

fixes #24626

Release note (sql fix): Fix problems with using tables
created in the same transaction when the tables have FOREIGN
KEY or INTERLEAVED references to other tables which have also
been created in the same transaction.

@vivekmenezes vivekmenezes requested review from a team and madelynnblue May 21, 2018 21:34
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@vivekmenezes vivekmenezes force-pushed the checktxn branch 3 times, most recently from 6496547 to 50d49d8 Compare May 22, 2018 08:50
@vivekmenezes
Copy link
Copy Markdown
Contributor Author

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented May 22, 2018

Build failed

@vivekmenezes
Copy link
Copy Markdown
Contributor Author

bors r-

Normally a table with references (FK, interleaved) is
placed in the ADD state to allow the referenced tables
to be upgraded with backreferences across the cluster,
before the cluster sees the ADD table in the PUBLIC state.
When all the table references are created in the same
transaction the table can be made PUBLIC immediately
because all the references are still not visible to
the cluster. This is particularly valuable when commands
within a transaction need to use the PUBLIC table and
will normally barf on seeing a table in the ADD state.

This also fixes a problem with column backfill in the
presence of FKs.

fixes cockroachdb#24626

Release note (sql fix): Fix problems with using tables
created in the same transaction when the tables have FOREIGN
KEY or INTERLEAVED references to other tables which have also
been created in the same transaction.
@vivekmenezes
Copy link
Copy Markdown
Contributor Author

bors r+

craig bot pushed a commit that referenced this pull request May 22, 2018
25786: sql: make table PUBLIC when references created in transaction r=vivekmenezes a=vivekmenezes

Normally a table with references (FK, interleaved) is
placed in the ADD state to allow the referenced tables
to be upgraded with backreferences across the cluster,
before the cluster sees the ADD table in the PUBLIC state.
When all the table references are created in the same
transaction the table can be made PUBLIC immediately
because all the references are still not visible to
the cluster. This is particularly valuable when commands
within a transaction need to use the PUBLIC table and
will normally barf on seeing a table in the ADD state.

This also fixes a problem with column backfill in the
presence of FKs.

fixes #24626

Release note (sql fix): Fix problems with using tables
created in the same transaction when the tables have FOREIGN
KEY or INTERLEAVED references to other tables which have also
been created in the same transaction.

Co-authored-by: Vivek Menezes <vivek@cockroachlabs.com>
@craig
Copy link
Copy Markdown
Contributor

craig bot commented May 22, 2018

Build succeeded

@craig craig bot merged commit d959e17 into cockroachdb:master May 22, 2018
@vivekmenezes vivekmenezes deleted the checktxn branch May 22, 2018 10:34
evalCtx *tree.EvalContext,
tableDesc *sqlbase.TableDescriptor,
) error {
// A column backfill in the ADD state is a noop.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure?

What about:

BEGIN;
CREATE TABLE blah ...;
INSERT INTO blah VALUES ...;
CREATE INDEX blih ON blah (...);  -- this needs a backfill!
COMMIT;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If TABLE blah is in the ADD state, the INSERT will fail

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I see thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sql: can't create table, index and foreign key in the same transaction

4 participants