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

fix expression round trip bug #1560

Merged
merged 4 commits into from
Jan 26, 2023
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
48 changes: 31 additions & 17 deletions enginetest/queries/query_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -14984,11 +14984,13 @@ WHERE id IN ('1', '2', '3')`,
" └─ Delete\n" +
" └─ Filter\n" +
" ├─ HashIn\n" +
" │ ├─ HGMQ6.id\n" +
" │ └─ ('1', '2', '3')\n" +
" └─ IndexedTableAccess(HGMQ6)\n" +
" │ ├─ HGMQ6.id:0!null\n" +
" │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" └─ IndexedTableAccess\n" +
" ├─ index: [HGMQ6.id]\n" +
" └─ filters: [{[2, 2]}, {[3, 3]}, {[1, 1]}]\n" +
" ├─ static: [{[2, 2]}, {[3, 3]}, {[1, 1]}]\n" +
" └─ Table\n" +
" └─ name: HGMQ6\n" +
"",
},
{
Expand Down Expand Up @@ -15067,27 +15069,37 @@ SET nd.KNG7T = (SELECT gn.id FROM WE72E gn INNER JOIN TDRVG ltnm ON ltnm.SSHPJ =
WHERE nd.FGG57 IS NOT NULL AND nd.KNG7T IS NULL`,
ExpectedPlan: "RowUpdateAccumulator\n" +
" └─ Update\n" +
" └─ UpdateSource(SET nd.KNG7T = Subquery\n" +
" └─ UpdateSource(SET nd.KNG7T:2 = Subquery\n" +
" ├─ cacheable: false\n" +
" └─ Project\n" +
" ├─ columns: [gn.id]\n" +
" ├─ columns: [gn.id:17!null]\n" +
" └─ Filter\n" +
" ├─ (ltnm.FGG57 = nd.FGG57)\n" +
" ├─ Eq\n" +
" │ ├─ ltnm.FGG57:22!null\n" +
" │ └─ nd.FGG57:6\n" +
" └─ LookupJoin\n" +
" ├─ (ltnm.SSHPJ = gn.SSHPJ)\n" +
" ├─ Eq\n" +
" │ ├─ ltnm.SSHPJ:23!null\n" +
" │ └─ gn.SSHPJ:19!null\n" +
" ├─ TableAlias(gn)\n" +
" │ └─ Table\n" +
" │ └─ name: WE72E\n" +
" └─ TableAlias(ltnm)\n" +
" └─ IndexedTableAccess(TDRVG)\n" +
" └─ index: [TDRVG.SSHPJ]\n" +
" └─ IndexedTableAccess\n" +
" ├─ index: [TDRVG.SSHPJ]\n" +
" └─ Table\n" +
" └─ name: TDRVG\n" +
" )\n" +
" └─ Filter\n" +
" ├─ ((NOT(nd.FGG57 IS NULL)) AND nd.KNG7T IS NULL)\n" +
" ├─ AND\n" +
" │ ├─ (NOT(nd.FGG57:6 IS NULL))\n" +
" │ └─ nd.KNG7T:2 IS NULL\n" +
" └─ TableAlias(nd)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" └─ IndexedTableAccess\n" +
" ├─ index: [E2I7U.FGG57]\n" +
" └─ filters: [{(NULL, ∞)}]\n" +
" ├─ static: [{(NULL, ∞)}]\n" +
" └─ Table\n" +
" └─ name: E2I7U\n" +
"",
},
{
Expand Down Expand Up @@ -16518,8 +16530,9 @@ FROM (
INNER JOIN D34QP vc ON C6PUD.AZ6SP LIKE CONCAT(CONCAT('%', vc.TWMSR), '%')`,
ExpectedPlan: "RowUpdateAccumulator\n" +
" └─ Insert(id, Z7CP5, YH4XB)\n" +
" ├─ Table\n" +
" │ └─ name: SEQS3\n" +
" ├─ InsertDestination\n" +
" │ └─ Table\n" +
" │ └─ name: SEQS3\n" +
" └─ Project\n" +
" ├─ columns: [id:0!null, Z7CP5:1!null, YH4XB:2!null]\n" +
" └─ Project\n" +
Expand Down Expand Up @@ -16662,8 +16675,9 @@ FROM
) BPNW2`,
ExpectedPlan: "RowUpdateAccumulator\n" +
" └─ Insert(id, FV24E, UJ6XY, M22QN, NZ4MQ, ETPQV, PRUV2, YKSSU, FHCYT)\n" +
" ├─ Table\n" +
" │ └─ name: HDDVB\n" +
" ├─ InsertDestination\n" +
" │ └─ Table\n" +
" │ └─ name: HDDVB\n" +
" └─ Project\n" +
" ├─ columns: [id:0!null, FV24E:1!null, UJ6XY:2!null, M22QN:3!null, NZ4MQ:4!null, ETPQV:5, PRUV2:6, YKSSU:7, FHCYT:8]\n" +
" └─ Union distinct\n" +
Expand Down
13 changes: 3 additions & 10 deletions sql/expression/in.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,8 @@ func (in *InTuple) WithChildren(children ...sql.Expression) (sql.Expression, err
}

func (in *InTuple) String() string {
pr := sql.NewTreePrinter()
_ = pr.WriteNode("IN")
children := []string{fmt.Sprintf("left: %s", in.Left()), fmt.Sprintf("right: %s", in.Right())}
_ = pr.WriteChildren(children...)
return pr.String()
// scalar expression must round-trip
return fmt.Sprintf("(%s IN %s)", in.Left(), in.Right())
}

func (in *InTuple) DebugString() string {
Expand Down Expand Up @@ -310,11 +307,7 @@ func convertOrTruncate(ctx *sql.Context, i interface{}, t sql.Type) (interface{}
}

func (hit *HashInTuple) String() string {
pr := sql.NewTreePrinter()
_ = pr.WriteNode("HashIn")
children := []string{hit.Left().String(), hit.Right().String()}
_ = pr.WriteChildren(children...)
return pr.String()
return fmt.Sprintf("(%s HASH IN %s)", hit.Left(), hit.Right())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one you can leave alone if you want, it should never show up in something like show create table

}

func (hit *HashInTuple) DebugString() string {
Expand Down
15 changes: 15 additions & 0 deletions sql/expression/in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"time"

"github.com/dolthub/vitess/go/sqltypes"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/src-d/go-errors.v1"

Expand All @@ -32,6 +33,20 @@ var testEnumType = types.MustCreateEnumType([]string{"", "one", "two"}, sql.Coll

var testSetType = types.MustCreateSetType([]string{"", "one", "two"}, sql.Collation_Default)

func TestRoundTripNames(t *testing.T) {
assert.Equal(t, "(foo IN (foo, 2))", expression.NewInTuple(expression.NewGetField(0, types.Int64, "foo", false),
expression.NewTuple(
expression.NewGetField(0, types.Int64, "foo", false),
expression.NewLiteral(int64(2), types.Int64),
)).String())
hit, err := expression.NewHashInTuple(nil, expression.NewGetField(0, types.Int64, "foo", false),
expression.NewTuple(
expression.NewLiteral(int64(2), types.Int64),
))
assert.NoError(t, err)
assert.Equal(t, "(foo HASH IN (2))", hit.String())
}

func TestInTuple(t *testing.T) {
testCases := []struct {
name string
Expand Down
4 changes: 4 additions & 0 deletions sql/plan/foreign_key_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func (n *ForeignKeyHandler) String() string {
return n.OriginalNode.String()
}

func (n *ForeignKeyHandler) DebugString() string {
return sql.DebugString(n.OriginalNode)
}

// Schema implements the interface sql.Node.
func (n *ForeignKeyHandler) Schema() sql.Schema {
return n.OriginalNode.Schema()
Expand Down