Skip to content

Commit

Permalink
opt: Update column formatting and rewrite all opt tests
Browse files Browse the repository at this point in the history
This removes the hack added in the previous commit so that the new
column formatting rules can work. We now only qualify column names if
it was explicitly requested via a formatting flag, or else if not
qualifying would result in ambiguous column names, such as in this
case:

  select a.x, b.x from a, b where a.x=b.x

Release note: None
  • Loading branch information
andy-kimball committed Aug 15, 2018
1 parent ecabf9f commit d59acf3
Show file tree
Hide file tree
Showing 83 changed files with 2,568 additions and 2,574 deletions.
4 changes: 2 additions & 2 deletions pkg/sql/opt/memo/expr_view_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func formatCol(f *ExprFmtCtx, label string, id opt.ColumnID, notNullCols opt.Col
md := f.Memo.metadata
if label == "" {
fullyQualify := !f.HasFlags(ExprFmtHideQualifications)
label = md.QualifiedColumnLabel(id, fullyQualify, false /* useTable */)
label = md.QualifiedColumnLabel(id, fullyQualify)
}

if !isSimpleColumnName(label) {
Expand Down Expand Up @@ -505,7 +505,7 @@ func formatPrivate(f *ExprFmtCtx, private interface{}, physProps *props.Physical

case opt.ColumnID:
fullyQualify := !f.HasFlags(ExprFmtHideQualifications)
label := f.Memo.metadata.QualifiedColumnLabel(t, fullyQualify, true /* useTable */)
label := f.Memo.metadata.QualifiedColumnLabel(t, fullyQualify)
fmt.Fprintf(f.Buffer, " %s", label)

case *IndexJoinDef:
Expand Down
138 changes: 69 additions & 69 deletions pkg/sql/opt/memo/testdata/logprops/constraints

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions pkg/sql/opt/memo/testdata/logprops/constraints-null
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ select
│ └── interesting orderings: ()
└── filters [type=bool, outer=(1), constraints=(/1: [/NULL - /NULL]; tight), fd=()-->(1)]
└── is [type=bool, outer=(1), constraints=(/1: [/NULL - /NULL]; tight)]
├── variable: t.a [type=int, outer=(1)]
├── variable: a [type=int, outer=(1)]
└── null [type=unknown]

opt
Expand All @@ -65,7 +65,7 @@ select
│ └── interesting orderings: ()
└── filters [type=bool, outer=(1), constraints=(/1: (/NULL - ]; tight)]
└── is-not [type=bool, outer=(1), constraints=(/1: (/NULL - ]; tight)]
├── variable: t.a [type=int, outer=(1)]
├── variable: a [type=int, outer=(1)]
└── null [type=unknown]

opt
Expand All @@ -84,10 +84,10 @@ select
│ └── interesting orderings: ()
└── filters [type=bool, outer=(2,3), constraints=(/2: [/NULL - /NULL]; /3: [/NULL - /NULL]; tight), fd=()-->(2,3)]
├── is [type=bool, outer=(2), constraints=(/2: [/NULL - /NULL]; tight)]
│ ├── variable: t.b [type=bool, outer=(2)]
│ ├── variable: b [type=bool, outer=(2)]
│ └── null [type=unknown]
└── is [type=bool, outer=(3), constraints=(/3: [/NULL - /NULL]; tight)]
├── variable: t.c [type=string, outer=(3)]
├── variable: c [type=string, outer=(3)]
└── null [type=unknown]

opt
Expand All @@ -105,10 +105,10 @@ select
│ └── interesting orderings: ()
└── filters [type=bool, outer=(2,3), constraints=(/2: (/NULL - ]; /3: (/NULL - ]; tight)]
├── is-not [type=bool, outer=(2), constraints=(/2: (/NULL - ]; tight)]
│ ├── variable: t.b [type=bool, outer=(2)]
│ ├── variable: b [type=bool, outer=(2)]
│ └── null [type=unknown]
└── is-not [type=bool, outer=(3), constraints=(/3: (/NULL - ]; tight)]
├── variable: t.c [type=string, outer=(3)]
├── variable: c [type=string, outer=(3)]
└── null [type=unknown]

exec-ddl
Expand Down Expand Up @@ -139,9 +139,9 @@ select
│ └── interesting orderings: ()
└── filters [type=bool, outer=(1,2), constraints=(/1: (/NULL - ])]
└── gt [type=bool, outer=(1,2), constraints=(/1: (/NULL - ])]
├── variable: xy.x [type=int, outer=(1)]
├── variable: x [type=int, outer=(1)]
└── function: abs [type=int, outer=(2)]
└── variable: xy.y [type=int, outer=(2)]
└── variable: y [type=int, outer=(2)]

# Test that we get a not-NULL constraint on x.
opt
Expand All @@ -159,11 +159,11 @@ select
│ └── interesting orderings: ()
└── filters [type=bool, outer=(1), constraints=(/1: (/NULL - ])]
└── gt [type=bool, outer=(1), constraints=(/1: (/NULL - ])]
├── variable: xy.x [type=int, outer=(1)]
├── variable: x [type=int, outer=(1)]
└── cast: INT [type=int, outer=(1)]
└── function: sin [type=float, outer=(1)]
└── cast: FLOAT [type=float, outer=(1)]
└── variable: xy.x [type=int, outer=(1)]
└── variable: x [type=int, outer=(1)]

# Test that we get a not-NULL constraint on x and y.
opt
Expand All @@ -180,8 +180,8 @@ select
│ └── interesting orderings: ()
└── filters [type=bool, outer=(1,2), constraints=(/1: (/NULL - ]; /2: (/NULL - ])]
└── gt [type=bool, outer=(1,2), constraints=(/1: (/NULL - ]; /2: (/NULL - ])]
├── variable: xy.x [type=int, outer=(1)]
└── variable: xy.y [type=int, outer=(2)]
├── variable: x [type=int, outer=(1)]
└── variable: y [type=int, outer=(2)]

# Test that we get a not-NULL constraint on x and y.
opt
Expand All @@ -199,5 +199,5 @@ select
│ └── interesting orderings: ()
└── filters [type=bool, outer=(1,2), constraints=(/1: (/NULL - ]; /2: (/NULL - ]), fd=(1)==(2), (2)==(1)]
└── eq [type=bool, outer=(1,2), constraints=(/1: (/NULL - ]; /2: (/NULL - ])]
├── variable: xy.x [type=int, outer=(1)]
└── variable: xy.y [type=int, outer=(2)]
├── variable: x [type=int, outer=(1)]
└── variable: y [type=int, outer=(2)]
14 changes: 7 additions & 7 deletions pkg/sql/opt/memo/testdata/logprops/groupby
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ project
│ │ └── interesting orderings: (+1) (-4,+3,+1)
│ └── aggregations [outer=(3)]
│ └── sum [type=float, outer=(3)]
│ └── variable: xyzs.z [type=float, outer=(3)]
│ └── variable: z [type=float, outer=(3)]
└── projections [outer=(1,2,5)]
└── false [type=bool]

Expand Down Expand Up @@ -88,9 +88,9 @@ scalar-group-by
│ └── interesting orderings: (+1) (-4,+3,+1)
└── aggregations [outer=(1,2)]
├── sum [type=decimal, outer=(1)]
│ └── variable: xyzs.x [type=int, outer=(1)]
│ └── variable: x [type=int, outer=(1)]
└── max [type=int, outer=(2)]
└── variable: xyzs.y [type=int, outer=(2)]
└── variable: y [type=int, outer=(2)]

# Group by unique index columns.
build
Expand Down Expand Up @@ -148,7 +148,7 @@ project
│ └── interesting orderings: (+1) (-4,+3,+1)
└── aggregations [outer=(3)]
└── sum [type=float, outer=(3)]
└── variable: xyzs.z [type=float, outer=(3)]
└── variable: z [type=float, outer=(3)]

# Group by column that is subset of unique index.
build
Expand All @@ -175,7 +175,7 @@ group-by
│ └── interesting orderings: (+1) (-4,+3,+1)
└── aggregations [outer=(4)]
└── max [type=string, outer=(4)]
└── variable: xyzs.s [type=string, outer=(4)]
└── variable: s [type=string, outer=(4)]

# Group by all columns.
build
Expand Down Expand Up @@ -316,6 +316,6 @@ group-by
│ └── interesting orderings: (+1)
└── aggregations [outer=(1,3)]
├── count [type=int, outer=(3)]
│ └── variable: xyzs.z [type=float, outer=(3)]
│ └── variable: z [type=float, outer=(3)]
└── const-agg [type=int, outer=(1)]
└── variable: xyzs.x [type=int, outer=(1)]
└── variable: x [type=int, outer=(1)]
10 changes: 5 additions & 5 deletions pkg/sql/opt/memo/testdata/logprops/index-join
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ select
└── filters [type=bool, outer=(1,2)]
└── eq [type=bool, outer=(1,2)]
├── plus [type=int, outer=(1,2)]
│ ├── variable: a.x [type=int, outer=(1)]
│ └── variable: a.y [type=int, outer=(2)]
│ ├── variable: x [type=int, outer=(1)]
│ └── variable: y [type=int, outer=(2)]
└── const: 10 [type=int]

opt
Expand Down Expand Up @@ -110,8 +110,8 @@ project
└── filters [type=bool, outer=(1,2)]
└── eq [type=bool, outer=(1,2)]
├── plus [type=int, outer=(1,2)]
│ ├── variable: a.x [type=int, outer=(1)]
│ └── variable: a.y [type=int, outer=(2)]
│ ├── variable: x [type=int, outer=(1)]
│ └── variable: y [type=int, outer=(2)]
└── const: 10 [type=int]

# Use secondary index to join to multi-valued primary index, but project only
Expand Down Expand Up @@ -140,5 +140,5 @@ select
│ └── interesting orderings: (+1,+2) (+3,+1,+2)
└── filters [type=bool, outer=(4), constraints=(/4: [/2 - /2]; tight), fd=()-->(4)]
└── eq [type=bool, outer=(4), constraints=(/4: [/2 - /2]; tight)]
├── variable: abc.d [type=int, outer=(4)]
├── variable: d [type=int, outer=(4)]
└── const: 2 [type=int]
Loading

0 comments on commit d59acf3

Please sign in to comment.