Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
130895: tree: fix walkStmt for SHOW EXPERIMENTAL_FINGERPRINTS r=rafiss a=rafiss

If SHOW EXPERIMENTAL_FINGERPRINTS FROM TABLE appeared in certain kinds of subqueries, the CRDB node could panic while walking the statement due to a missing nil check.

No release note since this only affected an experimental feature.

fixes #130822
Release note: None

130896: tree: disallow creating partial index while table is used in LDR r=rafiss a=rafiss

Epic: CRDB-38974
Release note: None

Co-authored-by: Rafi Shamim <[email protected]>
  • Loading branch information
craig[bot] and rafiss committed Sep 17, 2024
3 parents 40b4ad8 + e248fcc + 3516990 commit 832ba88
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pkg/sql/sem/tree/schema_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func IsSetOrResetSchemaLocked(n Statement) bool {
func IsAllowedLDRSchemaChange(n Statement) bool {
switch s := n.(type) {
case *CreateIndex:
// Only allow non-unique indexes to be created. A unique index on a
// destination table could cause inserts to fail.
return !s.Unique
// Only allow non-unique and non-partial indexes to be created. A unique or
// partial index on a destination table could cause inserts to fail.
return !s.Unique && s.Predicate == nil
case *DropIndex:
return true
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/sql/sem/tree/schema_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func TestIsAllowedLDRSchemaChange(t *testing.T) {
stmt: "CREATE UNIQUE INDEX idx ON t (a)",
isAllowed: false,
},
{
stmt: "CREATE INDEX idx ON t (a) WHERE a > 10",
isAllowed: false,
},
{
stmt: "DROP INDEX idx",
isAllowed: true,
Expand Down
12 changes: 7 additions & 5 deletions pkg/sql/sem/tree/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -1152,12 +1152,14 @@ func (n *ShowFingerprints) copyNode() *ShowFingerprints {
// walkStmt is part of the walkableStmt interface.
func (n *ShowFingerprints) walkStmt(v Visitor) Statement {
ret := n
ts, changed := walkTenantSpec(v, n.TenantSpec)
if changed {
if ret == n {
ret = n.copyNode()
if n.TenantSpec != nil {
ts, changed := walkTenantSpec(v, n.TenantSpec)
if changed {
if ret == n {
ret = n.copyNode()
}
ret.TenantSpec = ts
}
ret.TenantSpec = ts
}
if n.Options.StartTimestamp != nil {
e, changed := WalkExpr(v, n.Options.StartTimestamp)
Expand Down
9 changes: 9 additions & 0 deletions pkg/testutils/sqlutils/pretty.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ func VerifyStatementPrettyRoundtrip(t *testing.T, sql string) {
for i := range stmts {
origStmt := stmts[i].AST
verifyStatementPrettyRoundTrip(t, sql, origStmt, false /* plpgsql */)

// Verify that the AST can be walked.
if _, err := tree.SimpleStmtVisit(
origStmt,
func(expr tree.Expr) (recurse bool, newExpr tree.Expr, err error) { return },
); err != nil {
t.Fatalf("cannot walk stmt %s %v", stmts[i].SQL, err)
}

}
}

Expand Down

0 comments on commit 832ba88

Please sign in to comment.