Skip to content

Commit

Permalink
sql: remove unnecessary casts in @@ operator type-checking
Browse files Browse the repository at this point in the history
Release note: None
  • Loading branch information
mgartner committed Apr 5, 2023
1 parent 3d96b13 commit 7cfbd81
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
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

0 comments on commit 7cfbd81

Please sign in to comment.