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

sql: remove unnecessary casts in @@ operator type-checking #100704

Merged
merged 1 commit into from
Apr 6, 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
21 changes: 16 additions & 5 deletions pkg/sql/logictest/testdata/logic_test/tsvector
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,10 @@ SELECT 'fat cats ate fat bats' @@ a FROM ab
----
false

statement error pq: syntax error in TSQuery: fat cats chased fat, out of shape rats
statement error pgcode 22023 unsupported comparison operator: <string> @@ <tsvector>
SELECT b @@ a::tsvector FROM ab

statement error pq: syntax error in TSQuery: fat cats chased fat, out of shape rats
statement error pgcode 22023 unsupported comparison operator: <tsvector> @@ <string>
SELECT a::tsvector @@ b FROM ab

query B
Expand All @@ -418,9 +418,20 @@ SELECT 'bats fats' @@ 'fat bat cat'
----
false

statement error pq: syntax error in TSQuery: fat cats chased fat, out of shape rats
query B
SELECT 'fat' @@ 'fat rats'::tsvector
----
true

# TODO(#75101): The error should be "syntax error in TSQuery".
statement error pgcode 22023 unsupported comparison operator: <string> @@ <tsvector>
SELECT 'fat cats chased fat, out of shape rats' @@ 'fat rats'::tsvector

statement error pq: syntax error in TSQuery: fat cats chased fat, out of shape rats
SELECT 'fat rats'::tsvector @@ 'fat cats chased fat, out of shape rats'
query B
SELECT 'fat rats'::tsvector @@ 'fat'
----
true

# TODO(#75101): The error should be "syntax error in TSQuery".
statement error pgcode 22023 unsupported comparison operator: <tsvector> @@ <string>
SELECT 'fat rats'::tsvector @@ 'fat cats chased fat, out of shape rats'
4 changes: 0 additions & 4 deletions pkg/sql/sem/tree/type_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -2345,8 +2345,6 @@ func typeCheckComparisonOp(
leftExprs := make(Exprs, 1)
leftExprs[0] = typedLeft
foldedLeft = &FuncExpr{Func: WrapFunction("to_tsvector"), Exprs: leftExprs, AggType: GeneralAgg}
} else if rightFamily == types.TSVectorFamily {
foldedLeft = &CastExpr{Expr: typedLeft, Type: types.TSQuery, SyntaxMode: CastShort}
}
}

Expand All @@ -2359,8 +2357,6 @@ func typeCheckComparisonOp(
rightExprs := make(Exprs, 1)
rightExprs[0] = typedRight
foldedRight = &FuncExpr{Func: WrapFunction(funcName), Exprs: rightExprs, AggType: GeneralAgg}
} else if leftFamily == types.TSVectorFamily {
foldedRight = &CastExpr{Expr: typedRight, Type: types.TSQuery, SyntaxMode: CastShort}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/sem/tree/type_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ func TestTypeCheck(t *testing.T) {
{`'a' @@ 'b'`, `to_tsvector('a':::STRING) @@ plainto_tsquery('b':::STRING)`},
{`'a' @@ 'b':::TSQUERY`, `to_tsvector('a':::STRING) @@ '''b''':::TSQUERY`},
{`'a':::TSQUERY @@ 'b'`, `'''a''':::TSQUERY @@ to_tsvector('b':::STRING)`},
{`'a' @@ 'b':::TSVECTOR`, `'a':::STRING::TSQUERY @@ '''b''':::TSVECTOR`},
{`'a':::TSVECTOR @@ 'b'`, `'''a''':::TSVECTOR @@ 'b':::STRING::TSQUERY`},
{`'a' @@ 'b':::TSVECTOR`, `'''a''':::TSQUERY @@ '''b''':::TSVECTOR`},
{`'a':::TSVECTOR @@ 'b'`, `'''a''':::TSVECTOR @@ '''b''':::TSQUERY`},
}
ctx := context.Background()
for _, d := range testData {
Expand Down