-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathalter_range.go
62 lines (52 loc) · 1.98 KB
/
alter_range.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2018 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package optbuilder
import (
"github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo"
"github.com/cockroachdb/cockroach/pkg/sql/opt/memo"
"github.com/cockroachdb/cockroach/pkg/sql/opt/props/physical"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/types"
)
// buildAlterTableRelocate builds an ALTER RANGE RELOCATE (LEASE).
func (b *Builder) buildAlterRangeRelocate(
relocate *tree.RelocateRange, inScope *scope,
) (outScope *scope) {
if err := b.catalog.RequireAdminRole(b.ctx, "ALTER RANGE RELOCATE"); err != nil {
panic(err)
}
b.DisableMemoReuse = true
outScope = inScope.push()
b.synthesizeResultColumns(outScope, colinfo.AlterTableRelocateColumns)
cmdName := "RELOCATE"
if relocate.RelocateLease {
cmdName += " LEASE"
}
colNames := []string{"range ids"}
colTypes := []*types.T{types.Int}
outScope = inScope.push()
b.synthesizeResultColumns(outScope, colinfo.AlterRangeRelocateColumns)
// We don't allow the input statement to reference outer columns, so we
// pass a "blank" scope rather than inScope.
inputScope := b.buildStmt(relocate.Rows, colTypes, b.allocScope())
checkInputColumns(cmdName, inputScope, colNames, colTypes, 1)
outScope.expr = b.factory.ConstructAlterRangeRelocate(
inputScope.expr.(memo.RelExpr),
&memo.AlterRangeRelocatePrivate{
RelocateLease: relocate.RelocateLease,
RelocateNonVoters: relocate.RelocateNonVoters,
ToStoreID: relocate.ToStoreID,
FromStoreID: relocate.FromStoreID,
Columns: colsToColList(outScope.cols),
Props: physical.MinRequired,
},
)
return outScope
}