Skip to content

sql: materialized view created with incorrect fixed timestamp #79015

@ajwerner

Description

@ajwerner

Describe the problem

# Test CREATE MATERIALIZED VIEW referring to a sequence.
statement ok
CREATE SEQUENCE seq;
CREATE MATERIALIZED VIEW view_from_seq AS (SELECT nextval('seq'))
        /home/roach/.cache/bazel/_bazel_roach/c5a4e7d36696d9cd970af2045211a7df/sandbox/processwrapper-sandbox/4047/execroot/cockroach/bazel-out/k8-dbg/bin/pkg/sql/logictest/logictest_test_/logictest_test.runfiles/cockroach/pkg/sql/logictest/testdata/logic_test/materialized_view:214:
        expected success, but found
        (42P01) nextval(): relation "[115]" does not exist
        errors.go:161: in NewUndefinedRelationError()

https://teamcity.cockroachdb.com/buildConfiguration/Cockroach_GitHubCiOptional/4726513?buildTab=overview&showRootCauses=false&expandBuildProblemsSection=true&expandBuildTestsSection=true&expandBuildChangesSection=true

Seems like the root cause is if the transaction gets pushed, then the CreateAsOfTime will be before the other descriptors created in the same transaction. See

return sc.backfillQueryIntoTable(ctx, table, table.GetViewQuery(), table.GetCreateAsOfTime(), "materializedViewBackfill")
and

desc.CreateAsOfTime = params.p.Txn().ReadTimestamp()

The solution here is to remove the code which sets the creation time as we'll set it automatically when we read the descriptor for the first time.

Jira issue: CRDB-14500

Metadata

Metadata

Assignees

Labels

A-schema-descriptorsRelating to SQL table/db descriptor handling.C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions