Skip to content

Commit

Permalink
Merge #41037 #41042
Browse files Browse the repository at this point in the history
41037: stats: add logging to TestDefaultColumns to help debug flake r=rytaft a=rytaft

This commit adds some logging to the `TestDefaultColumns` test in order
to help debug a test failure.

Informs #38572

Release note: None
Release justification: category 1, non-production code change

41042: tree: fix LIKE suboperator with NULL LHS r=rafiss a=rafiss

If a NULL value was present in the LHS of a suboperator with a LIKE
comparison, then previously the server would crash with a panic. Now it
is handled and there are tests.

closes #40841

Release justification: Low impact bug fix that prevents a server crash.

Release note: None

Co-authored-by: Rebecca Taft <[email protected]>
Co-authored-by: Rafi Shamim <[email protected]>
  • Loading branch information
3 people committed Sep 24, 2019
3 parents dcc9a15 + 0d1d9da + 477d887 commit ec3947e
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/sql/sem/tree/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -2453,6 +2453,9 @@ func ConvertLikeToRegexp(
}

func matchLike(ctx *EvalContext, left, right Datum, caseInsensitive bool) (Datum, error) {
if left == DNull || right == DNull {
return DNull, nil
}
s, pattern := string(MustBeDString(left)), string(MustBeDString(right))
if len(s) == 0 {
// An empty string only matches with an empty pattern or a pattern
Expand Down
71 changes: 71 additions & 0 deletions pkg/sql/sem/tree/testdata/eval/any_some_all
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ eval
----
false

eval
'foo' LIKE ANY ARRAY[]
----
false

eval
'foo' LIKE ANY (ARRAY['bar', 'baz'])
----
false

eval
'foo' LIKE ANY (ARRAY['foo', 'bar', 'baz'])
----
true

eval
1+1 = SOME (ARRAY[1, 3, 4])
----
Expand All @@ -50,6 +65,21 @@ eval
----
true

eval
'foo' LIKE ALL ARRAY[]
----
true

eval
'foo' LIKE ALL (ARRAY['foo', 'bar', 'baz'])
----
false

eval
'foo' LIKE ALL (ARRAY['foo', 'foo'])
----
true

eval
1 = ANY (ARRAY[1, 2, NULL])
----
Expand Down Expand Up @@ -87,6 +117,11 @@ eval
----
NULL

eval
'foo' LIKE ANY(NULL::string[])
----
NULL

eval
NULL::int = ANY(NULL::int[])
----
Expand All @@ -102,6 +137,11 @@ NULL::int = ALL(NULL::int[])
----
NULL

eval
NULL::string LIKE ANY(NULL::string[])
----
NULL

# A null LHS has different behavior if the array is empty or not
eval
NULL::int = ANY(ARRAY[1,2])
Expand Down Expand Up @@ -133,6 +173,21 @@ NULL::int = ALL(ARRAY[]::int[])
----
true

eval
NULL::string LIKE ANY(ARRAY[]::string[])
----
false

eval
NULL::string LIKE SOME(ARRAY[]::string[])
----
false

eval
NULL::string LIKE ALL(ARRAY[]::string[])
----
true

eval
1 = ALL (ARRAY[1, 2, NULL])
----
Expand Down Expand Up @@ -232,3 +287,19 @@ eval
'aaa' NOT ILIKE ANY (ARRAY['%A%', '%A%'])
----
false

# Regression test for #40841 -- make sure LIKE can handle nulls.
eval
NULL::string LIKE ANY(ARRAY['bar', 'baz'])
----
NULL

eval
NULL::string ILIKE ANY(ARRAY['bar%', 'baz'])
----
NULL

eval
NULL::string LIKE ANY(ARRAY['bar', NULL])
----
NULL
11 changes: 11 additions & 0 deletions pkg/sql/stats/automatic_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,17 @@ func TestDefaultColumns(t *testing.T) {

sqlRun.Exec(t, `CREATE STATISTICS s FROM t.a`)

// TODO(rytaft): this extra logging was added to help debug issue #38572.
// Remove it once that issue is resolved.
// === BEGINNING OF EXTRA LOGGING ===
res := sqlRun.QueryStr(t, `SHOW CREATE TABLE t.a`)
t.Log(sqlutils.MatrixToStr(res))
res = sqlRun.QueryStr(t, `EXPLAIN (DISTSQL) CREATE STATISTICS s FROM t.a`)
t.Log(sqlutils.MatrixToStr(res))
res = sqlRun.QueryStr(t, `SHOW STATISTICS FOR TABLE t.a`)
t.Log(sqlutils.MatrixToStr(res))
// === END OF EXTRA LOGGING ===

// There should be 101 stats. One for the primary index, plus 100 other
// columns.
sqlRun.CheckQueryResults(t,
Expand Down

0 comments on commit ec3947e

Please sign in to comment.