mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
* fb-1940 re-implemented some changes that got missed private-public * fb-1939 fixes to between + decimals * fb-1935 - avg() on and id type + fixed some tests * fb-1953 add min/max for string types * fb-1938 - remove internal_type column from show columns * fb-1964 - fix space_used in fb_cluster_nodes to be int * fb-1996 - make sure all Idents that are being used as object references to schema objects are lowercased * fixed failing test * added some missed changes * fb-1969 found another case issue with identifier used for column idents
75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
// Copyright 2022 Molecula Corp. All rights reserved.
|
|
|
|
package planner
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"github.com/featurebasedb/featurebase/v3/sql3/parser"
|
|
"github.com/featurebasedb/featurebase/v3/sql3/planner/types"
|
|
)
|
|
|
|
// compileDeleteStatement compiles a parser.DeleteStatment AST into a PlanOperator
|
|
func (p *ExecutionPlanner) compileDeleteStatement(stmt *parser.DeleteStatement) (types.PlanOperator, error) {
|
|
query := NewPlanOpQuery(p, NewPlanOpNullTable(), p.sql)
|
|
|
|
tableName := strings.ToLower(parser.IdentName(stmt.TableName.Name))
|
|
|
|
// source expression
|
|
source, err := p.compileSource(query, stmt.Source)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// handle the where clause
|
|
where, err := p.compileExpr(stmt.WhereExpr)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
_, sourceIsScan := source.(*PlanOpPQLTableScan)
|
|
|
|
// no where clause and source is a scan so it's a truncate
|
|
if where == nil && sourceIsScan {
|
|
delOp := NewPlanOpPQLTruncateTable(p, string(tableName))
|
|
|
|
children := []types.PlanOperator{
|
|
delOp,
|
|
}
|
|
return query.WithChildren(children...)
|
|
}
|
|
|
|
var delOp types.PlanOperator
|
|
|
|
// if we did have a where, insert the filter op
|
|
if where != nil {
|
|
delOp = NewPlanOpPQLConstRowDelete(p, string(tableName), NewPlanOpFilter(p, where, source))
|
|
} else {
|
|
delOp = NewPlanOpPQLConstRowDelete(p, string(tableName), source)
|
|
}
|
|
|
|
children := []types.PlanOperator{
|
|
delOp,
|
|
}
|
|
return query.WithChildren(children...)
|
|
}
|
|
|
|
func (p *ExecutionPlanner) analyzeDeleteStatement(ctx context.Context, stmt *parser.DeleteStatement) error {
|
|
|
|
_, err := p.analyzeSource(ctx, stmt.Source, stmt)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// if we have a where clause, check that
|
|
if stmt.WhereExpr != nil {
|
|
expr, err := p.analyzeExpression(ctx, stmt.WhereExpr, stmt)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
stmt.WhereExpr = expr
|
|
}
|
|
|
|
return nil
|
|
}
|