Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
35700: sql: hints for CROSS JOIN r=RaduBerinde a=RaduBerinde

Adding support for cross join hints, for example `CROSS MERGE JOIN`.

Fixes cockroachdb#35695.

Release note (sql change): it is now possible to specify a HASH /
MERGE / LOOKUP join hint with cross joints (CROSS <hint> JOIN).

35739: stats: convert stats failure into warning r=rytaft a=rytaft

Prior to this commit, failure to successfully create automatic stats
for a table resulted in an error logged to the SQL shell. This commit
converts the error to a warning so that it is not printed in the shell.

Fixes cockroachdb#35668

Release note: None

Co-authored-by: Radu Berinde <[email protected]>
Co-authored-by: Rebecca Taft <[email protected]>
  • Loading branch information
3 people committed Mar 14, 2019
3 parents d8d92b7 + de1e43a + 8ba0b6c commit 8f9d022
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/generated/sql/bnf/joined_table.bnf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
joined_table ::=
'(' joined_table ')'
| table_ref 'CROSS' 'JOIN' table_ref
| table_ref 'CROSS' opt_join_hint 'JOIN' table_ref
| table_ref ( 'FULL' ( 'OUTER' | ) | 'LEFT' ( 'OUTER' | ) | 'RIGHT' ( 'OUTER' | ) | 'INNER' ) opt_join_hint 'JOIN' table_ref ( 'USING' '(' ( ( name ) ( ( ',' name ) )* ) ')' | 'ON' a_expr )
| table_ref 'JOIN' table_ref ( 'USING' '(' ( ( name ) ( ( ',' name ) )* ) ')' | 'ON' a_expr )
| table_ref 'NATURAL' ( 'FULL' ( 'OUTER' | ) | 'LEFT' ( 'OUTER' | ) | 'RIGHT' ( 'OUTER' | ) | 'INNER' ) opt_join_hint 'JOIN' table_ref
Expand Down
14 changes: 7 additions & 7 deletions docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -2024,7 +2024,7 @@ opt_alias_clause ::=

joined_table ::=
'(' joined_table ')'
| table_ref 'CROSS' 'JOIN' table_ref
| table_ref 'CROSS' opt_join_hint 'JOIN' table_ref
| table_ref join_type opt_join_hint 'JOIN' table_ref join_qual
| table_ref 'JOIN' table_ref join_qual
| table_ref 'NATURAL' join_type opt_join_hint 'JOIN' table_ref
Expand Down Expand Up @@ -2161,18 +2161,18 @@ char_aliases ::=
window_definition ::=
window_name 'AS' window_specification

join_type ::=
'FULL' join_outer
| 'LEFT' join_outer
| 'RIGHT' join_outer
| 'INNER'

opt_join_hint ::=
'HASH'
| 'MERGE'
| 'LOOKUP'
|

join_type ::=
'FULL' join_outer
| 'LEFT' join_outer
| 'RIGHT' join_outer
| 'INNER'

join_qual ::=
'USING' '(' name_list ')'
| 'ON' a_expr
Expand Down
39 changes: 39 additions & 0 deletions pkg/sql/opt/exec/execbuilder/testdata/join
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,45 @@ render · ·
· table twocolumn@primary
· spans ALL

# Test that we can force a merge join using the NATURAL syntax.
query TTT
EXPLAIN SELECT * FROM onecolumn NATURAL INNER MERGE JOIN twocolumn
----
render · ·
└── join · ·
│ type inner
│ equality (x) = (x)
│ mergeJoinOrder +"(x=x)"
├── sort · ·
│ │ order +x
│ └── scan · ·
│ table onecolumn@primary
│ spans ALL
└── sort · ·
│ order +x
└── scan · ·
· table twocolumn@primary
· spans ALL

# Test that we can force a merge join using the CROSS syntax.
query TTT
EXPLAIN SELECT * FROM onecolumn CROSS MERGE JOIN twocolumn WHERE onecolumn.x = twocolumn.x
----
join · ·
│ type inner
│ equality (x) = (x)
│ mergeJoinOrder +"(x=x)"
├── sort · ·
│ │ order +x
│ └── scan · ·
│ table onecolumn@primary
│ spans ALL
└── sort · ·
│ order +x
└── scan · ·
· table twocolumn@primary
· spans ALL

statement error LOOKUP can only be used with INNER or LEFT joins
EXPLAIN SELECT * FROM onecolumn RIGHT LOOKUP JOIN twocolumn USING(x)

Expand Down
1 change: 1 addition & 0 deletions pkg/sql/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ func TestParse(t *testing.T) {
{`SELECT a FROM t1 INNER JOIN t2 ON a = b`},
{`SELECT a FROM t1 INNER HASH JOIN t2 ON a = b`},
{`SELECT a FROM t1 CROSS JOIN t2`},
{`SELECT a FROM t1 CROSS LOOKUP JOIN t2`},
{`SELECT a FROM t1 NATURAL JOIN t2`},
{`SELECT a FROM t1 NATURAL INNER MERGE JOIN t2`},
{`SELECT a FROM t1 INNER JOIN t2 USING (a)`},
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -6053,9 +6053,9 @@ joined_table:
{
$$.val = &tree.ParenTableExpr{Expr: $2.tblExpr()}
}
| table_ref CROSS JOIN table_ref
| table_ref CROSS opt_join_hint JOIN table_ref
{
$$.val = &tree.JoinTableExpr{JoinType: tree.AstCross, Left: $1.tblExpr(), Right: $4.tblExpr()}
$$.val = &tree.JoinTableExpr{JoinType: tree.AstCross, Left: $1.tblExpr(), Right: $5.tblExpr(), Hint: $3}
}
| table_ref join_type opt_join_hint JOIN table_ref join_qual
{
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/stats/automatic_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func (r *Refresher) maybeRefreshStats(

// Log other errors but don't automatically reschedule the refresh, since
// that could lead to endless retries.
log.Errorf(ctx, "failed to create statistics on table %d: %v", tableID, err)
log.Warningf(ctx, "failed to create statistics on table %d: %v", tableID, err)
return
}
}
Expand Down

0 comments on commit 8f9d022

Please sign in to comment.