github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/sql/sem/tree/split.go (about) 1 // Copyright 2016 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package tree 12 13 // Split represents an `ALTER TABLE/INDEX .. SPLIT AT ..` statement. 14 type Split struct { 15 TableOrIndex TableIndexName 16 // Each row contains values for the columns in the PK or index (or a prefix 17 // of the columns). 18 Rows *Select 19 // Splits can last a specified amount of time before becoming eligible for 20 // automatic merging. 21 ExpireExpr Expr 22 } 23 24 // Format implements the NodeFormatter interface. 25 func (node *Split) Format(ctx *FmtCtx) { 26 ctx.WriteString("ALTER ") 27 if node.TableOrIndex.Index != "" { 28 ctx.WriteString("INDEX ") 29 } else { 30 ctx.WriteString("TABLE ") 31 } 32 ctx.FormatNode(&node.TableOrIndex) 33 ctx.WriteString(" SPLIT AT ") 34 ctx.FormatNode(node.Rows) 35 if node.ExpireExpr != nil { 36 ctx.WriteString(" WITH EXPIRATION ") 37 ctx.FormatNode(node.ExpireExpr) 38 } 39 } 40 41 // Unsplit represents an `ALTER TABLE/INDEX .. UNSPLIT AT ..` statement. 42 type Unsplit struct { 43 TableOrIndex TableIndexName 44 // Each row contains values for the columns in the PK or index (or a prefix 45 // of the columns). 46 Rows *Select 47 All bool 48 } 49 50 // Format implements the NodeFormatter interface. 51 func (node *Unsplit) Format(ctx *FmtCtx) { 52 ctx.WriteString("ALTER ") 53 if node.TableOrIndex.Index != "" { 54 ctx.WriteString("INDEX ") 55 } else { 56 ctx.WriteString("TABLE ") 57 } 58 ctx.FormatNode(&node.TableOrIndex) 59 if node.All { 60 ctx.WriteString(" UNSPLIT ALL") 61 } else { 62 ctx.WriteString(" UNSPLIT AT ") 63 ctx.FormatNode(node.Rows) 64 } 65 } 66 67 // Relocate represents an `ALTER TABLE/INDEX .. EXPERIMENTAL_RELOCATE ..` 68 // statement. 69 type Relocate struct { 70 // TODO(a-robinson): It's not great that this can only work on ranges that 71 // are part of a currently valid table or index. 72 TableOrIndex TableIndexName 73 // Each row contains an array with store ids and values for the columns in the 74 // PK or index (or a prefix of the columns). 75 // See docs/RFCS/sql_split_syntax.md. 76 Rows *Select 77 SubjectReplicas RelocateSubject 78 } 79 80 // Format implements the NodeFormatter interface. 81 func (node *Relocate) Format(ctx *FmtCtx) { 82 ctx.WriteString("ALTER ") 83 if node.TableOrIndex.Index != "" { 84 ctx.WriteString("INDEX ") 85 } else { 86 ctx.WriteString("TABLE ") 87 } 88 ctx.FormatNode(&node.TableOrIndex) 89 ctx.WriteString(" RELOCATE ") 90 ctx.FormatNode(&node.SubjectReplicas) 91 ctx.WriteByte(' ') 92 ctx.FormatNode(node.Rows) 93 } 94 95 // Scatter represents an `ALTER TABLE/INDEX .. SCATTER ..` 96 // statement. 97 type Scatter struct { 98 TableOrIndex TableIndexName 99 // Optional from and to values for the columns in the PK or index (or a prefix 100 // of the columns). 101 // See docs/RFCS/sql_split_syntax.md. 102 From, To Exprs 103 } 104 105 // Format implements the NodeFormatter interface. 106 func (node *Scatter) Format(ctx *FmtCtx) { 107 ctx.WriteString("ALTER ") 108 if node.TableOrIndex.Index != "" { 109 ctx.WriteString("INDEX ") 110 } else { 111 ctx.WriteString("TABLE ") 112 } 113 ctx.FormatNode(&node.TableOrIndex) 114 ctx.WriteString(" SCATTER") 115 if node.From != nil { 116 ctx.WriteString(" FROM (") 117 ctx.FormatNode(&node.From) 118 ctx.WriteString(") TO (") 119 ctx.FormatNode(&node.To) 120 ctx.WriteString(")") 121 } 122 }