github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/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 RelocateLease bool 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(" EXPERIMENTAL_RELOCATE ") 90 if node.RelocateLease { 91 ctx.WriteString("LEASE ") 92 } 93 ctx.FormatNode(node.Rows) 94 } 95 96 // Scatter represents an `ALTER TABLE/INDEX .. SCATTER ..` 97 // statement. 98 type Scatter struct { 99 TableOrIndex TableIndexName 100 // Optional from and to values for the columns in the PK or index (or a prefix 101 // of the columns). 102 // See docs/RFCS/sql_split_syntax.md. 103 From, To Exprs 104 } 105 106 // Format implements the NodeFormatter interface. 107 func (node *Scatter) Format(ctx *FmtCtx) { 108 ctx.WriteString("ALTER ") 109 if node.TableOrIndex.Index != "" { 110 ctx.WriteString("INDEX ") 111 } else { 112 ctx.WriteString("TABLE ") 113 } 114 ctx.FormatNode(&node.TableOrIndex) 115 ctx.WriteString(" SCATTER") 116 if node.From != nil { 117 ctx.WriteString(" FROM (") 118 ctx.FormatNode(&node.From) 119 ctx.WriteString(") TO (") 120 ctx.FormatNode(&node.To) 121 ctx.WriteString(")") 122 } 123 }