-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explicit unnecessary cast should be eliminated (#1984)
* Explicit unnecessary cast should be eliminated This commit can eliminate unnecessary explicit cast in where condition and tune the query to choose index in those conditions Task: BABEL-4176 Signed-off-by: Zhibai Song <[email protected]>
- Loading branch information
1 parent
1ca1f8c
commit 2104cc7
Showing
26 changed files
with
226 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
drop table cast_eliminate | ||
GO | ||
|
||
drop table cast_eliminate2 | ||
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE cast_eliminate( [ROID] [int] NOT NULL PRIMARY KEY ); | ||
GO | ||
|
||
CREATE TABLE cast_eliminate2( [ROID] [bigint] NOT NULL PRIMARY KEY ); | ||
GO | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
set babelfish_showplan_all on | ||
GO | ||
|
||
SELECT 1 AS [C1] FROM cast_eliminate WHERE (CAST(ROID AS BIGINT) = 1) | ||
GO | ||
~~START~~ | ||
text | ||
Query Text: SELECT 1 AS [C1] FROM cast_eliminate WHERE (CAST(ROID AS BIGINT) = 1) | ||
Index Only Scan using cast_eliminate_pkey on cast_eliminate (cost=0.15..8.17 rows=1 width=4) | ||
Index Cond: (roid = 1) | ||
~~END~~ | ||
|
||
|
||
SELECT 1 AS [C1] FROM cast_eliminate WHERE (CAST(ROID AS int) = 1) | ||
GO | ||
~~START~~ | ||
text | ||
Query Text: SELECT 1 AS [C1] FROM cast_eliminate WHERE (CAST(ROID AS int) = 1) | ||
Index Only Scan using cast_eliminate_pkey on cast_eliminate (cost=0.15..8.17 rows=1 width=4) | ||
Index Cond: (roid = 1) | ||
~~END~~ | ||
|
||
|
||
SELECT 1 AS [C1] FROM cast_eliminate WHERE (ROID = cast(1 as bigint)) | ||
GO | ||
~~START~~ | ||
text | ||
Query Text: SELECT 1 AS [C1] FROM cast_eliminate WHERE (ROID = cast(1 as bigint)) | ||
Index Only Scan using cast_eliminate_pkey on cast_eliminate (cost=0.15..8.17 rows=1 width=4) | ||
Index Cond: (roid = '1'::bigint) | ||
~~END~~ | ||
|
||
|
||
SELECT 1 AS [C1] FROM cast_eliminate WHERE (CAST(ROID AS BIGINT) = cast( 1 as bigint )) | ||
GO | ||
~~START~~ | ||
text | ||
Query Text: SELECT 1 AS [C1] FROM cast_eliminate WHERE (CAST(ROID AS BIGINT) = cast( 1 as bigint )) | ||
Index Only Scan using cast_eliminate_pkey on cast_eliminate (cost=0.15..8.17 rows=1 width=4) | ||
Index Cond: (roid = '1'::bigint) | ||
~~END~~ | ||
|
||
|
||
SELECT 1 AS [C1] FROM cast_eliminate2 WHERE (CAST(ROID AS BIGINT) = 1) | ||
GO | ||
~~START~~ | ||
text | ||
Query Text: SELECT 1 AS [C1] FROM cast_eliminate2 WHERE (CAST(ROID AS BIGINT) = 1) | ||
Index Only Scan using cast_eliminate2_pkey on cast_eliminate2 (cost=0.15..8.17 rows=1 width=4) | ||
Index Cond: (roid = 1) | ||
~~END~~ | ||
|
||
|
||
SELECT 1 AS [C1] FROM cast_eliminate2 WHERE (CAST(ROID AS int) = 1) | ||
GO | ||
~~START~~ | ||
text | ||
Query Text: SELECT 1 AS [C1] FROM cast_eliminate2 WHERE (CAST(ROID AS int) = 1) | ||
Seq Scan on cast_eliminate2 (cost=0.00..43.90 rows=11 width=4) | ||
Filter: ((roid)::integer = 1) | ||
~~END~~ | ||
|
||
|
||
SELECT 1 AS [C1] FROM cast_eliminate2 WHERE (ROID = cast(1 as bigint)) | ||
GO | ||
~~START~~ | ||
text | ||
Query Text: SELECT 1 AS [C1] FROM cast_eliminate2 WHERE (ROID = cast(1 as bigint)) | ||
Index Only Scan using cast_eliminate2_pkey on cast_eliminate2 (cost=0.15..8.17 rows=1 width=4) | ||
Index Cond: (roid = '1'::bigint) | ||
~~END~~ | ||
|
||
|
||
SELECT 1 AS [C1] FROM cast_eliminate WHERE (CAST(ROID AS BIGINT) = cast( 1 as bigint )) | ||
GO | ||
~~START~~ | ||
text | ||
Query Text: SELECT 1 AS [C1] FROM cast_eliminate WHERE (CAST(ROID AS BIGINT) = cast( 1 as bigint )) | ||
Index Only Scan using cast_eliminate_pkey on cast_eliminate (cost=0.15..8.17 rows=1 width=4) | ||
Index Cond: (roid = '1'::bigint) | ||
~~END~~ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
drop table cast_eliminate | ||
GO | ||
|
||
drop table cast_eliminate2 | ||
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE cast_eliminate( [ROID] [int] NOT NULL PRIMARY KEY ); | ||
GO | ||
|
||
CREATE TABLE cast_eliminate2( [ROID] [bigint] NOT NULL PRIMARY KEY ); | ||
GO | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
set babelfish_showplan_all on | ||
GO | ||
|
||
SELECT 1 AS [C1] FROM cast_eliminate WHERE (CAST(ROID AS BIGINT) = 1) | ||
GO | ||
|
||
SELECT 1 AS [C1] FROM cast_eliminate WHERE (CAST(ROID AS int) = 1) | ||
GO | ||
|
||
SELECT 1 AS [C1] FROM cast_eliminate WHERE (ROID = cast(1 as bigint)) | ||
GO | ||
|
||
SELECT 1 AS [C1] FROM cast_eliminate WHERE (CAST(ROID AS BIGINT) = cast( 1 as bigint )) | ||
GO | ||
|
||
SELECT 1 AS [C1] FROM cast_eliminate2 WHERE (CAST(ROID AS BIGINT) = 1) | ||
GO | ||
|
||
SELECT 1 AS [C1] FROM cast_eliminate2 WHERE (CAST(ROID AS int) = 1) | ||
GO | ||
|
||
SELECT 1 AS [C1] FROM cast_eliminate2 WHERE (ROID = cast(1 as bigint)) | ||
GO | ||
|
||
SELECT 1 AS [C1] FROM cast_eliminate WHERE (CAST(ROID AS BIGINT) = cast( 1 as bigint )) | ||
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -322,3 +322,4 @@ getdate | |
BABEL-4410 | ||
GRANT_SCHEMA | ||
AUTO_ANALYZE-before-15-5-or-14-10 | ||
cast_eliminate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -413,3 +413,4 @@ BABEL-4384 | |
GRANT_SCHEMA | ||
default_params | ||
BABEL-3326 | ||
cast_eliminate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -340,3 +340,4 @@ BABEL-2619 | |
BABEL-4410 | ||
GRANT_SCHEMA | ||
AUTO_ANALYZE-before-15-5-or-14-10 | ||
cast_eliminate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -355,3 +355,4 @@ BABEL-2619 | |
BABEL-4410 | ||
GRANT_SCHEMA | ||
AUTO_ANALYZE-before-15-5-or-14-10 | ||
cast_eliminate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -407,4 +407,5 @@ getdate | |
BABEL_4330 | ||
BABEL-2619 | ||
AUTO_ANALYZE-before-15-5-or-14-10 | ||
default_params | ||
default_params | ||
cast_eliminate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -386,4 +386,5 @@ BABEL-4046 | |
getdate | ||
BABEL_4330 | ||
AUTO_ANALYZE-before-15-5-or-14-10 | ||
default_params | ||
default_params | ||
cast_eliminate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -418,3 +418,4 @@ BABEL-4410 | |
GRANT_SCHEMA | ||
AUTO_ANALYZE-before-15-5-or-14-10 | ||
default_params | ||
cast_eliminate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -438,4 +438,5 @@ BABEL-4046 | |
getdate | ||
BABEL_4330 | ||
AUTO_ANALYZE-before-15-5-or-14-10 | ||
default_params | ||
default_params | ||
cast_eliminate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.