Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opt: support ALTER TABLE UNSPLIT and EXPERIMENTAL_RELOCATE #38653

Merged
merged 2 commits into from
Jul 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pkg/sql/opt/bench/stub_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,19 @@ func (f *stubFactory) ConstructAlterTableSplit(
) (exec.Node, error) {
return struct{}{}, nil
}

func (f *stubFactory) ConstructAlterTableUnsplit(
index cat.Index, input exec.Node,
) (exec.Node, error) {
return struct{}{}, nil
}

func (f *stubFactory) ConstructAlterTableUnsplitAll(index cat.Index) (exec.Node, error) {
return struct{}{}, nil
}

func (f *stubFactory) ConstructAlterTableRelocate(
index cat.Index, input exec.Node, relocateLease bool,
) (exec.Node, error) {
return struct{}{}, nil
}
9 changes: 9 additions & 0 deletions pkg/sql/opt/exec/execbuilder/relational.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,15 @@ func (b *Builder) buildRelational(e memo.RelExpr) (execPlan, error) {
case *memo.AlterTableSplitExpr:
ep, err = b.buildAlterTableSplit(t)

case *memo.AlterTableUnsplitExpr:
ep, err = b.buildAlterTableUnsplit(t)

case *memo.AlterTableUnsplitAllExpr:
ep, err = b.buildAlterTableUnsplitAll(t)

case *memo.AlterTableRelocateExpr:
ep, err = b.buildAlterTableRelocate(t)

default:
if opt.IsSetOp(e) {
ep, err = b.buildSetOp(e)
Expand Down
56 changes: 56 additions & 0 deletions pkg/sql/opt/exec/execbuilder/statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,59 @@ func (b *Builder) buildAlterTableSplit(split *memo.AlterTableSplitExpr) (execPla
}
return ep, nil
}

func (b *Builder) buildAlterTableUnsplit(unsplit *memo.AlterTableUnsplitExpr) (execPlan, error) {
input, err := b.buildRelational(unsplit.Input)
if err != nil {
return execPlan{}, err
}
table := b.mem.Metadata().Table(unsplit.Table)
node, err := b.factory.ConstructAlterTableUnsplit(
table.Index(unsplit.Index),
input.root,
)
if err != nil {
return execPlan{}, err
}
ep := execPlan{root: node}
for i, c := range unsplit.Columns {
ep.outputCols.Set(int(c), i)
}
return ep, nil
}

func (b *Builder) buildAlterTableUnsplitAll(
unsplitAll *memo.AlterTableUnsplitAllExpr,
) (execPlan, error) {
table := b.mem.Metadata().Table(unsplitAll.Table)
node, err := b.factory.ConstructAlterTableUnsplitAll(table.Index(unsplitAll.Index))
if err != nil {
return execPlan{}, err
}
ep := execPlan{root: node}
for i, c := range unsplitAll.Columns {
ep.outputCols.Set(int(c), i)
}
return ep, nil
}

func (b *Builder) buildAlterTableRelocate(relocate *memo.AlterTableRelocateExpr) (execPlan, error) {
input, err := b.buildRelational(relocate.Input)
if err != nil {
return execPlan{}, err
}
table := b.mem.Metadata().Table(relocate.Table)
node, err := b.factory.ConstructAlterTableRelocate(
table.Index(relocate.Index),
input.root,
relocate.RelocateLease,
)
if err != nil {
return execPlan{}, err
}
ep := execPlan{root: node}
for i, c := range relocate.Columns {
ep.outputCols.Set(int(c), i)
}
return ep, nil
}
12 changes: 12 additions & 0 deletions pkg/sql/opt/exec/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,18 @@ type Factory interface {
// ConstructAlterTableSplit creates a node that implements ALTER TABLE/INDEX
// SPLIT AT.
ConstructAlterTableSplit(index cat.Index, input Node, expiration tree.TypedExpr) (Node, error)

// ConstructAlterTableUnsplit creates a node that implements ALTER TABLE/INDEX
// UNSPLIT AT.
ConstructAlterTableUnsplit(index cat.Index, input Node) (Node, error)

// ConstructAlterTableUnsplitAll creates a node that implements ALTER TABLE/INDEX
// UNSPLIT ALL.
ConstructAlterTableUnsplitAll(index cat.Index) (Node, error)

// ConstructAlterTableRelocate creates a node that implements ALTER TABLE/INDEX
// UNSPLIT AT.
ConstructAlterTableRelocate(index cat.Index, input Node, relocateLease bool) (Node, error)
}

// OutputOrdering indicates the required output ordering on a Node that is being
Expand Down
9 changes: 8 additions & 1 deletion pkg/sql/opt/memo/expr_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ func (f *ExprFmtCtx) formatRelational(e RelExpr, tp treeprinter.Node) {

case *ScanExpr, *VirtualScanExpr, *IndexJoinExpr, *ShowTraceForSessionExpr,
*InsertExpr, *UpdateExpr, *UpsertExpr, *DeleteExpr, *SequenceSelectExpr,
*WindowExpr, *OpaqueRelExpr:
*WindowExpr, *OpaqueRelExpr, *AlterTableSplitExpr, *AlterTableUnsplitExpr,
*AlterTableUnsplitAllExpr, *AlterTableRelocateExpr:
fmt.Fprintf(f.Buffer, "%v", e.Op())
FormatPrivate(f, e.Private(), required)

Expand Down Expand Up @@ -981,6 +982,12 @@ func FormatPrivate(f *ExprFmtCtx, private interface{}, physProps *physical.Requi
fmt.Fprintf(f.Buffer, " %s@%s", tableAlias(f, t.Table), tab.Index(t.Index).Name())
}

case *AlterTableRelocatePrivate:
FormatPrivate(f, &t.AlterTableSplitPrivate, nil)
if t.RelocateLease {
f.Buffer.WriteString(" [lease]")
}

case *JoinPrivate:
// Nothing to show; flags are shown separately.

Expand Down
24 changes: 24 additions & 0 deletions pkg/sql/opt/memo/logical_props_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,30 @@ func (b *logicalPropsBuilder) buildAlterTableSplitProps(
rel.CanMutate = true
}

func (b *logicalPropsBuilder) buildAlterTableUnsplitProps(
unsplit *AlterTableUnsplitExpr, rel *props.Relational,
) {
b.buildBasicProps(unsplit, unsplit.Columns, rel)
rel.CanHaveSideEffects = true
rel.CanMutate = true
}

func (b *logicalPropsBuilder) buildAlterTableUnsplitAllProps(
unsplitAll *AlterTableUnsplitAllExpr, rel *props.Relational,
) {
b.buildBasicProps(unsplitAll, unsplitAll.Columns, rel)
rel.CanHaveSideEffects = true
rel.CanMutate = true
}

func (b *logicalPropsBuilder) buildAlterTableRelocateProps(
relocate *AlterTableRelocateExpr, rel *props.Relational,
) {
b.buildBasicProps(relocate, relocate.Columns, rel)
rel.CanHaveSideEffects = true
rel.CanMutate = true
}

func (b *logicalPropsBuilder) buildLimitProps(limit *LimitExpr, rel *props.Relational) {
BuildSharedProps(b.mem, limit, &rel.Shared)

Expand Down
32 changes: 32 additions & 0 deletions pkg/sql/opt/ops/statement.opt
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,35 @@ define AlterTableSplitPrivate {
# Columns stores the column IDs for the statement result columns.
Columns ColList
}

# AlterTableUnsplit represents an `ALTER TABLE/INDEX .. UNSPLIT AT ..`
# statement.
[Relational, DDL]
define AlterTableUnsplit {
Input RelExpr

_ AlterTableSplitPrivate
}

# AlterTableUnsplit represents an `ALTER TABLE/INDEX .. UNSPLIT ALL` statement.
[Relational, DDL]
define AlterTableUnsplitAll {
_ AlterTableSplitPrivate
}

# AlterTableRelocate represents an `ALTER TABLE/INDEX .. SPLIT AT ..` statement.
[Relational, DDL]
define AlterTableRelocate {
# The input expression provides values for the index columns (or a prefix of
# them).
Input RelExpr

_ AlterTableRelocatePrivate
}

[Private]
define AlterTableRelocatePrivate {
RelocateLease bool

_ AlterTableSplitPrivate
}
Loading