You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/11/10 15:47:58 UTC

[GitHub] [shardingsphere] ThanoshanMV opened a new pull request #13546: Add SQLServer EXPLAIN statement

ThanoshanMV opened a new pull request #13546:
URL: https://github.com/apache/shardingsphere/pull/13546


   For #6478
   
   Hi @jingshanglu, I've added SQLServer [EXPLAIN](https://docs.microsoft.com/en-us/sql/t-sql/queries/explain-transact-sql?view=azure-sqldw-latest#syntax) statement. Please check it. I'll change them based on your feedback.
   
   Changes proposed in this pull request:
   - Add SQLServer `EXPLAIN` statement.
   - Add corresponding test cases.
   - In the `EXPLAIN` statement, `SQL_statement` can contain [CREATE TABLE AS SELECT](https://docs.microsoft.com/en-us/sql/t-sql/statements/create-table-as-select-azure-sql-data-warehouse?view=aps-pdw-2016-au7) and [CREATE REMOTE TABLE](https://docs.microsoft.com/en-us/sql/t-sql/statements/create-remote-table-as-select-parallel-data-warehouse?view=aps-pdw-2016-au7) as well. As these statements are not available now, I'll add them in the next PRs.
   - I've moved the methods that belong to `SELECT`, `UPDATE`, `DELETE` and `INSERT` to `SQLServerStatementSQLVisitor` so that `SQLServerDALStatementSQLVisitor` can also utilize them.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] ThanoshanMV commented on pull request #13546: Add SQLServer EXPLAIN statement

Posted by GitBox <gi...@apache.org>.
ThanoshanMV commented on pull request #13546:
URL: https://github.com/apache/shardingsphere/pull/13546#issuecomment-972622774


   > Hi @jingshanglu, I added `CREATE TABLE AS SELECT` statement within the existing `CREATE TABLE` statement (#13628). `EXPLAIN` statement's `SQL_statement` can have `CREATE TABLE AS SELECT`.
   > 
   > * Can we have `explainableStatement` like below:
   > 
   > ```
   > explainableStatement
   >     : select | insert | update | delete | createTable
   >     ;
   > ```
   > 
   > But the above definition would allow parsing normal `CREATE TABLE` statements too. Please let me know what do you think.
   
   Hi @jingshanglu, what can we do in the above situation


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] jingshanglu commented on a change in pull request #13546: Add SQLServer EXPLAIN statement

Posted by GitBox <gi...@apache.org>.
jingshanglu commented on a change in pull request #13546:
URL: https://github.com/apache/shardingsphere/pull/13546#discussion_r747150295



##########
File path: shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/explain.xml
##########
@@ -17,8 +17,9 @@
   -->
 
 <sql-cases>
-    <sql-case id="explain_select_constant_without_table" value="EXPLAIN SELECT 1 as a" db-types="PostgreSQL,openGauss, MySQL" />
-    <sql-case id="explain_update_without_condition" value="EXPLAIN UPDATE t_order SET status = 'finished'" db-types="PostgreSQL,openGauss, MySQL" />
-    <sql-case id="explain_insert_without_parameters" value="EXPLAIN INSERT INTO t_order (order_id, user_id, status) VALUES (1, 1, 'insert')" db-types="PostgreSQL,openGauss, MySQL" />
-    <sql-case id="explain_delete_without_sharding_value" value="EXPLAIN DELETE FROM t_order WHERE status='init'" db-types="PostgreSQL,openGauss, MySQL" />
+    <sql-case id="explain_select_constant_without_table" value="EXPLAIN SELECT 1 as a" db-types="PostgreSQL, openGauss, MySQL, SQLServer" />
+    <sql-case id="explain_update_without_condition" value="EXPLAIN UPDATE t_order SET status = 'finished'" db-types="PostgreSQL, openGauss, MySQL, SQLServer" />
+    <sql-case id="explain_insert_without_parameters" value="EXPLAIN INSERT INTO t_order (order_id, user_id, status) VALUES (1, 1, 'insert')" db-types="PostgreSQL, openGauss, MySQL, SQLServer" />
+    <sql-case id="explain_delete_without_sharding_value" value="EXPLAIN DELETE FROM t_order WHERE status='init'" db-types="PostgreSQL, openGauss, MySQL, SQLServer" />
+    <sql-case id="explain_select_with_binding_tables" value="EXPLAIN SELECT G.StateProvinceName, T.SalesTerritoryGroup FROM dbo.DimGeography AS G JOIN dbo.DimSalesTerritory AS T ON G.SalesTerritoryKey = T.SalesTerritoryKey WHERE T.SalesTerritoryGroup IN ('North America', 'Pacific')" db-types="SQLServer" />

Review comment:
       @ThanoshanMV It may be better to use a uniform table name, such as `t_order`.

##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/DALStatement.g4
##########
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+grammar DALStatement;
+
+import SQLServerKeyword, DMLStatement;
+
+explain
+    : EXPLAIN WITH_RECOMMENDATIONS? explainableStatement
+    ;
+
+explainableStatement
+    : (select | insert | update | delete)
+    ;

Review comment:
       @ThanoshanMV It might be better to simplify to this
   ```
   explainableStatement
       : select | insert | update | delete
       ;
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] codecov-commenter commented on pull request #13546: Add SQLServer EXPLAIN statement

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #13546:
URL: https://github.com/apache/shardingsphere/pull/13546#issuecomment-965732361


   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/13546?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#13546](https://codecov.io/gh/apache/shardingsphere/pull/13546?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (b42e0ba) into [master](https://codecov.io/gh/apache/shardingsphere/commit/34629fbef220053621235a1adf7a6539b660b7c0?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (34629fb) will **increase** coverage by `0.01%`.
   > The diff coverage is `85.77%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/13546/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/shardingsphere/pull/13546?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #13546      +/-   ##
   ============================================
   + Coverage     63.77%   63.78%   +0.01%     
   - Complexity     1651     1652       +1     
   ============================================
     Files          2705     2706       +1     
     Lines         40426    40437      +11     
     Branches       6910     6913       +3     
   ============================================
   + Hits          25780    25794      +14     
   + Misses        12692    12690       -2     
   + Partials       1954     1953       -1     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/13546?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...tatement/impl/SQLServerDMLStatementSQLVisitor.java](https://codecov.io/gh/apache/shardingsphere/pull/13546/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLWRpYWxlY3Qvc2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci1zcWxzZXJ2ZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3NxbC9wYXJzZXIvc3Fsc2VydmVyL3Zpc2l0b3Ivc3RhdGVtZW50L2ltcGwvU1FMU2VydmVyRE1MU3RhdGVtZW50U1FMVmlzaXRvci5qYXZh) | `100.00% <ø> (+14.70%)` | :arrow_up: |
   | [...ement/sqlserver/dal/SQLServerExplainStatement.java](https://codecov.io/gh/apache/shardingsphere/pull/13546/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLXN0YXRlbWVudC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc3FsL3BhcnNlci9zcWwvZGlhbGVjdC9zdGF0ZW1lbnQvc3Fsc2VydmVyL2RhbC9TUUxTZXJ2ZXJFeHBsYWluU3RhdGVtZW50LmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...r/statement/impl/SQLServerStatementSQLVisitor.java](https://codecov.io/gh/apache/shardingsphere/pull/13546/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLWRpYWxlY3Qvc2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci1zcWxzZXJ2ZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3NxbC9wYXJzZXIvc3Fsc2VydmVyL3Zpc2l0b3Ivc3RhdGVtZW50L2ltcGwvU1FMU2VydmVyU3RhdGVtZW50U1FMVmlzaXRvci5qYXZh) | `79.59% <85.53%> (+4.59%)` | :arrow_up: |
   | [...tatement/impl/SQLServerDALStatementSQLVisitor.java](https://codecov.io/gh/apache/shardingsphere/pull/13546/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLWRpYWxlY3Qvc2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci1zcWxzZXJ2ZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3NxbC9wYXJzZXIvc3Fsc2VydmVyL3Zpc2l0b3Ivc3RhdGVtZW50L2ltcGwvU1FMU2VydmVyREFMU3RhdGVtZW50U1FMVmlzaXRvci5qYXZh) | `100.00% <100.00%> (+100.00%)` | :arrow_up: |
   | [...ent/facade/SQLServerStatementSQLVisitorFacade.java](https://codecov.io/gh/apache/shardingsphere/pull/13546/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLWRpYWxlY3Qvc2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci1zcWxzZXJ2ZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3NxbC9wYXJzZXIvc3Fsc2VydmVyL3Zpc2l0b3Ivc3RhdGVtZW50L2ZhY2FkZS9TUUxTZXJ2ZXJTdGF0ZW1lbnRTUUxWaXNpdG9yRmFjYWRlLmphdmE=) | `88.88% <0.00%> (+11.11%)` | :arrow_up: |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/13546?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/13546?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [34629fb...b42e0ba](https://codecov.io/gh/apache/shardingsphere/pull/13546?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] ThanoshanMV commented on a change in pull request #13546: Add SQLServer EXPLAIN statement

Posted by GitBox <gi...@apache.org>.
ThanoshanMV commented on a change in pull request #13546:
URL: https://github.com/apache/shardingsphere/pull/13546#discussion_r747528108



##########
File path: shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/explain.xml
##########
@@ -17,8 +17,9 @@
   -->
 
 <sql-cases>
-    <sql-case id="explain_select_constant_without_table" value="EXPLAIN SELECT 1 as a" db-types="PostgreSQL,openGauss, MySQL" />
-    <sql-case id="explain_update_without_condition" value="EXPLAIN UPDATE t_order SET status = 'finished'" db-types="PostgreSQL,openGauss, MySQL" />
-    <sql-case id="explain_insert_without_parameters" value="EXPLAIN INSERT INTO t_order (order_id, user_id, status) VALUES (1, 1, 'insert')" db-types="PostgreSQL,openGauss, MySQL" />
-    <sql-case id="explain_delete_without_sharding_value" value="EXPLAIN DELETE FROM t_order WHERE status='init'" db-types="PostgreSQL,openGauss, MySQL" />
+    <sql-case id="explain_select_constant_without_table" value="EXPLAIN SELECT 1 as a" db-types="PostgreSQL, openGauss, MySQL, SQLServer" />
+    <sql-case id="explain_update_without_condition" value="EXPLAIN UPDATE t_order SET status = 'finished'" db-types="PostgreSQL, openGauss, MySQL, SQLServer" />
+    <sql-case id="explain_insert_without_parameters" value="EXPLAIN INSERT INTO t_order (order_id, user_id, status) VALUES (1, 1, 'insert')" db-types="PostgreSQL, openGauss, MySQL, SQLServer" />
+    <sql-case id="explain_delete_without_sharding_value" value="EXPLAIN DELETE FROM t_order WHERE status='init'" db-types="PostgreSQL, openGauss, MySQL, SQLServer" />
+    <sql-case id="explain_select_with_binding_tables" value="EXPLAIN SELECT G.StateProvinceName, T.SalesTerritoryGroup FROM dbo.DimGeography AS G JOIN dbo.DimSalesTerritory AS T ON G.SalesTerritoryKey = T.SalesTerritoryKey WHERE T.SalesTerritoryGroup IN ('North America', 'Pacific')" db-types="SQLServer" />

Review comment:
       @jingshanglu, I've modified them.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] ThanoshanMV commented on pull request #13546: Add SQLServer EXPLAIN statement

Posted by GitBox <gi...@apache.org>.
ThanoshanMV commented on pull request #13546:
URL: https://github.com/apache/shardingsphere/pull/13546#issuecomment-969967608


   Hi @jingshanglu, I added `CREATE TABLE AS SELECT` statement within the existing `CREATE TABLE` statement (#13628). `EXPLAIN` statement's `SQL_statement` can have `CREATE TABLE AS SELECT`.
   
   - Can we have `explainableStatement` like below:
   ```
   explainableStatement
       : select | insert | update | delete | createTable
       ;
   ```
   
   But the above definition would allow parsing normal `CREATE TABLE` statements too. Please let me know what do you think.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] jingshanglu commented on pull request #13546: Add SQLServer EXPLAIN statement

Posted by GitBox <gi...@apache.org>.
jingshanglu commented on pull request #13546:
URL: https://github.com/apache/shardingsphere/pull/13546#issuecomment-966752055


   LGTM


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] jingshanglu merged pull request #13546: Add SQLServer EXPLAIN statement

Posted by GitBox <gi...@apache.org>.
jingshanglu merged pull request #13546:
URL: https://github.com/apache/shardingsphere/pull/13546


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org