sql: add support for MATERIALIZED VIEW with AS OF SYSTEM TIME#142259
sql: add support for MATERIALIZED VIEW with AS OF SYSTEM TIME#142259craig[bot] merged 1 commit intocockroachdb:masterfrom
Conversation
|
Your pull request contains more than 1000 changes. It is strongly encouraged to split big PRs into smaller chunks. It looks like your PR touches SQL parser code but doesn't add or edit parser tests. Please make sure you add or edit parser tests if you edit the parser. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
f8d0f39 to
0338396
Compare
|
It looks like your PR touches SQL parser code but doesn't add or edit parser tests. Please make sure you add or edit parser tests if you edit the parser. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
0338396 to
b1b5132
Compare
fqazi
left a comment
There was a problem hiding this comment.
Great work, just one suggestion for a test.
Reviewed 15 of 15 files at r1, all commit messages.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @spilchen)
pkg/sql/logictest/testdata/logic_test/materialized_view line 329 at r1 (raw file):
statement ok REFRESH MATERIALIZED VIEW mat_view_as_of AS OF SYSTEM TIME '$ts_after_drop_c'
Should we validate if before object creation?
spilchen
left a comment
There was a problem hiding this comment.
Looks good. I just had a few questions.
Reviewed all commit messages.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @rafiss)
pkg/sql/create_view.go line 230 at r1 (raw file):
} if creationTime.Less(mostRecentModTime) {
Is there any concurrency issue here if one of the dependent tables is changed immediately after this check? I assume once this create view commits, then other schema changes on the dependent tables will pick up the dependency. But what if the schema change and create view are happening at the same time?
pkg/sql/opt/optbuilder/create_view.go line 117 at r1 (raw file):
Syntax: cv, Schema: schID, // We need the view query to include user-defined types as a 3-part name to
nit: should this comment be removed? I think it was copied above, which seems like a better place for it.
pkg/sql/logictest/testdata/logic_test/materialized_view line 275 at r1 (raw file):
statement ok CREATE MATERIALIZED VIEW mat_view_as_of AS SELECT a FROM tab_as_of AS OF SYSTEM TIME '$ts_before_insert_1'
If I understand it correctly, the ASOF time applies only during the refresh of the MQT. Is it valid to specify an ASOF time and request NO DATA? For instance, is this something that we allow:
CREATE MATERIALIZED VIEW v1 AS SELECT * FROM tab_as_of AS OF SYSTEM TIME '-5s' WITH NO DATA
rafiss
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @fqazi and @spilchen)
pkg/sql/create_view.go line 230 at r1 (raw file):
Previously, spilchen wrote…
Is there any concurrency issue here if one of the dependent tables is changed immediately after this check? I assume once this create view commits, then other schema changes on the dependent tables will pick up the dependency. But what if the schema change and create view are happening at the same time?
i believe we should be safe here. since this operation modifies the backrefs on the dependent tables, and a competing schema change would need to make its own modifications to the table descriptor, that means at commit time only one of them will be able to succeed.
pkg/sql/opt/optbuilder/create_view.go line 117 at r1 (raw file):
Previously, spilchen wrote…
nit: should this comment be removed? I think it was copied above, which seems like a better place for it.
done
pkg/sql/logictest/testdata/logic_test/materialized_view line 275 at r1 (raw file):
Previously, spilchen wrote…
If I understand it correctly, the ASOF time applies only during the refresh of the MQT. Is it valid to specify an ASOF time and request NO DATA? For instance, is this something that we allow:
CREATE MATERIALIZED VIEW v1 AS SELECT * FROM tab_as_of AS OF SYSTEM TIME '-5s' WITH NO DATA
good question. i added a test case for this, and although i don't see why anyone would want to use it, i don't see a reason to disallow it, as it still makes sense semantically.
pkg/sql/logictest/testdata/logic_test/materialized_view line 329 at r1 (raw file):
Previously, fqazi (Faizan Qazi) wrote…
Should we validate if before object creation?
i added a test.
Release note (sql change): Statements such as REFRESH MATERIALIZED VIEW and CREATE MATERIALIZED VIEW can now be executed with an AS OF SYSTEM TIME clause. These statements can still not be used in an explicit transaction.
rafiss
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @fqazi and @spilchen)
pkg/sql/create_view.go line 230 at r1 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
i believe we should be safe here. since this operation modifies the backrefs on the dependent tables, and a competing schema change would need to make its own modifications to the table descriptor, that means at commit time only one of them will be able to succeed.
i tested this manually and the correct thing happened. i started the CREATE MATERIALIZED VIEW, then made it sleep after this check. then i ran an ALTER TABLE on the dependent table in a different session. this ALTER TABLE succeeded.
when the CREATE MATERIALIZED VIEW unpaused, it resumed execution, but encountered a transaction retry error. the CREATE MATERIALIZED VIEW was automatically retried, and on this second attempt it failed this check so returned the correct error.
b1b5132 to
2932e59
Compare
|
TFTRs! bors r+ |
Release note (sql change): Statements such as REFRESH MATERIALIZED VIEW
and CREATE MATERIALIZED VIEW can now be executed with an AS OF SYSTEM
TIME clause. These statements can still not be used in an explicit
transaction.
fixes #96391