You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "TherChenYang (via GitHub)" <gi...@apache.org> on 2024/01/04 14:30:28 UTC

[PR] 29158 [shardingsphere]

TherChenYang opened a new pull request, #29655:
URL: https://github.com/apache/shardingsphere/pull/29655

   Fixes #29158.
   
   Changes proposed in this pull request:
     - Add support for parse update statistics [official website link](https://learn.microsoft.com/zh-cn/sql/t-sql/statements/update-statistics-transact-sql?view=sql-server-ver16)
     - Add update statistics statement
     - Add update statistics assert 
   ![image](https://github.com/apache/shardingsphere/assets/124348939/6bc9ce32-ffc2-4219-8cde-9089169331d3)
   ---
   Support for the following update statistics sql 
   
   **update_statistics_with_no_index**
   ```sql
   UPDATE STATISTICS Sales.SalesOrderDetail;
   ```
   **update_statistics_with_full_scan**
   ```sql
   UPDATE STATISTICS Customer (CustomerStats1) WITH FULLSCAN;
   ```
   **update_statistics_with_auto_drop**
   ```sql
   UPDATE STATISTICS Customer (CustomerStats1) WITH AUTO_DROP = ON;
   ```
   **update_statistics_with_sample**
   ```sql
   UPDATE STATISTICS Production.Product(Products) WITH SAMPLE 50 PERCENT;
   ```
   **update_statistics_with_full_scan_no_recompute**
   ```sql
   UPDATE STATISTICS Production.Product(Products) WITH FULLSCAN, NORECOMPUTE;
   ```
   **update_statistics_with_resample_on_partitions**
   ```sql
   UPDATE STATISTICS dbo.PartitionIncrStatDemo(IX_PartitionIncrStatDemo_ID) WITH RESAMPLE ON PARTITIONS(3)
   ```
   ---
   Support for the following  sql  in #29158
   ```sql
   SELECT -- Find an event you want.
       p.name AS [Package-Name],
       o.object_type,
       o.name AS [Object-Name],
       o.description AS [Object-Descr],
       p.guid AS [Package-Guid]
   FROM sys.dm_xe_packages AS p
   INNER JOIN sys.dm_xe_objects AS o
       ON p.guid = o.package_guid
   WHERE o.object_type = 'event' --'action'  --'target'
       AND p.name LIKE '%'
       AND o.name LIKE '%sql%'
   ORDER BY p.name,
       o.object_type,
       o.name
   ```
   
   ```sql
   SELECT ProductId, Name, value
   FROM Product
       CROSS APPLY STRING_SPLIT(Tags, ',')
   ```
   
   ```sql
   SELECT value as tag, COUNT(*) AS [number_of_articles]
   FROM Product
       CROSS APPLY STRING_SPLIT(Tags, ',')
   GROUP BY value
   HAVING COUNT(*) > 2
   ORDER BY COUNT(*) DESC
   ```
   ---
   
   Before committing this PR, I'm sure that I have checked the following options:
   - [x] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
   - [x] I have self-reviewed the commit code.
   - [ ] I have (or in comment I request) added corresponding labels for the pull request.
   - [x] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
   - [ ] I have made corresponding changes to the documentation.
   - [x] I have added corresponding unit tests for my changes.
   


-- 
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


Re: [PR] Support for SQLServer parse update statistics sql [shardingsphere]

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu merged PR #29655:
URL: https://github.com/apache/shardingsphere/pull/29655


-- 
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


Re: [PR] Support for SQLServer parse update statistics sql [shardingsphere]

Posted by "TherChenYang (via GitHub)" <gi...@apache.org>.
TherChenYang commented on PR #29655:
URL: https://github.com/apache/shardingsphere/pull/29655#issuecomment-1879996218

   @strongduanmu  I have made adjustments, please take another look.


-- 
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


Re: [PR] Support for SQLServer parse update statistics sql [shardingsphere]

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu commented on code in PR #29655:
URL: https://github.com/apache/shardingsphere/pull/29655#discussion_r1442436511


##########
parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/SQLServerStatementVisitor.java:
##########
@@ -1338,4 +1350,99 @@ public ASTNode visitCreateTableAsSelectClause(final CreateTableAsSelectClauseCon
         }
         return result;
     }
+    
+    @Override
+    public ASTNode visitUpdateStatistics(final UpdateStatisticsContext ctx) {
+        SQLServerUpdateStatisticsStatement result = new SQLServerUpdateStatisticsStatement();
+        if (null != ctx.tableName()) {
+            result.setTable((SimpleTableSegment) visit(ctx.tableName()));
+        }
+        if (null != ctx.indexName() && ctx.indexName().size() > 0) {
+            List<IndexSegment> indexSegments = new LinkedList<>();
+            for (IndexNameContext indexNameContext : ctx.indexName()) {
+                indexSegments.add((IndexSegment) visit(indexNameContext));
+            }
+            result.setIndexes(indexSegments);
+        }
+        if (null != ctx.statisticsWithClause()) {
+            result.setStrategy((StatisticsStrategySegment) visit(ctx.statisticsWithClause()));
+        }
+        return result;
+    }
+    
+    @Override
+    public ASTNode visitStatisticsWithClause(final StatisticsWithClauseContext ctx) {
+        StatisticsStrategySegment segment = new StatisticsStrategySegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex());
+        if (null != ctx.sampleOption()) {
+            segment.setSampleOption((SampleOptionSegment) visit(ctx.sampleOption()));
+        }
+        if (null != ctx.statisticsOptions()) {
+            segment.setStatisticsOptions((StatisticsOptionSegment) visit(ctx.statisticsOptions()));
+        }
+        return segment;

Review Comment:
   Please rename segment to result.



##########
parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/SQLServerStatementVisitor.java:
##########
@@ -1338,4 +1350,99 @@ public ASTNode visitCreateTableAsSelectClause(final CreateTableAsSelectClauseCon
         }
         return result;
     }
+    
+    @Override
+    public ASTNode visitUpdateStatistics(final UpdateStatisticsContext ctx) {
+        SQLServerUpdateStatisticsStatement result = new SQLServerUpdateStatisticsStatement();
+        if (null != ctx.tableName()) {
+            result.setTable((SimpleTableSegment) visit(ctx.tableName()));
+        }
+        if (null != ctx.indexName() && ctx.indexName().size() > 0) {
+            List<IndexSegment> indexSegments = new LinkedList<>();
+            for (IndexNameContext indexNameContext : ctx.indexName()) {
+                indexSegments.add((IndexSegment) visit(indexNameContext));
+            }
+            result.setIndexes(indexSegments);
+        }
+        if (null != ctx.statisticsWithClause()) {
+            result.setStrategy((StatisticsStrategySegment) visit(ctx.statisticsWithClause()));
+        }
+        return result;
+    }
+    
+    @Override
+    public ASTNode visitStatisticsWithClause(final StatisticsWithClauseContext ctx) {
+        StatisticsStrategySegment segment = new StatisticsStrategySegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex());
+        if (null != ctx.sampleOption()) {
+            segment.setSampleOption((SampleOptionSegment) visit(ctx.sampleOption()));
+        }
+        if (null != ctx.statisticsOptions()) {
+            segment.setStatisticsOptions((StatisticsOptionSegment) visit(ctx.statisticsOptions()));
+        }
+        return segment;
+    }
+    
+    @Override
+    public ASTNode visitStatisticsOption(final StatisticsOptionContext ctx) {
+        return super.visitStatisticsOption(ctx);
+    }
+    
+    @Override
+    public ASTNode visitSampleOption(final SampleOptionContext ctx) {
+        SampleOptionSegment segment = new SampleOptionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex());
+        if (null != ctx.FULLSCAN()) {
+            segment.setStrategy(SampleStrategy.FULLSCAN);
+        } else if (null != ctx.SAMPLE()) {
+            segment.setStrategy(SampleStrategy.SAMPLE);
+            if (null != ctx.NUMBER_()) {
+                List<TerminalNode> number = ctx.NUMBER_();
+                segment.setSampleNumber(number.get(0).getText());
+            }
+            if (null != ctx.PERCENT()) {
+                segment.setScanUnit(ScanUnit.PERCENT);
+            } else if (null != ctx.ROWS()) {
+                segment.setScanUnit(ScanUnit.ROWS);
+            }
+        } else if (null != ctx.RESAMPLE()) {
+            segment.setStrategy(SampleStrategy.RESAMPLE);
+            if (null != ctx.NUMBER_()) {
+                List<String> partitions = new LinkedList<>();
+                for (TerminalNode terminalNode : ctx.NUMBER_()) {
+                    partitions.add(terminalNode.getText());
+                }
+                segment.setPartitions(partitions);
+            }
+        }
+        if (null != ctx.PERSIST_SAMPLE_PERCENT()) {
+            segment.setPersistSamplePercent(null != ctx.ON());
+        }
+        return segment;
+    }
+    
+    @Override
+    public ASTNode visitStatisticsOptions(final StatisticsOptionsContext ctx) {
+        StatisticsOptionSegment optionSegment = new StatisticsOptionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex());
+        for (StatisticsOptionContext option : ctx.statisticsOption()) {
+            if (null != option.ALL()) {
+                optionSegment.setStatisticsDimension(StatisticsDimension.ALL);
+            } else if (null != option.COLUMNS()) {
+                optionSegment.setStatisticsDimension(StatisticsDimension.COLUMNS);
+            } else if (null != option.INDEX()) {
+                optionSegment.setStatisticsDimension(StatisticsDimension.INDEX);
+            }
+            if (null != option.NORECOMPUTE()) {
+                optionSegment.setNoRecompute(true);
+            }
+            if (null != option.INCREMENTAL()) {
+                optionSegment.setIncremental(null != option.ON());
+            }
+            if (null != option.MAXDOP()) {
+                optionSegment.setMaxDegreeOfParallelism(option.NUMBER_().getText());
+            }
+            if (null != option.AUTO_DROP()) {
+                optionSegment.setAutoDrop(null != option.ON());
+            }
+        }
+        return optionSegment;

Review Comment:
   Please rename segment to result.



##########
parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/sqlserver/segment/SampleOptionSegment.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+
+package org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.segment;
+
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.SQLSegment;
+
+import java.util.List;
+
+@Getter
+@Setter
+@NoArgsConstructor
+public final class SampleOptionSegment implements SQLSegment {

Review Comment:
   Please add javadoc for this class.



##########
parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/sqlserver/segment/StatisticsDimension.java:
##########
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+package org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.segment;
+
+public enum StatisticsDimension {

Review Comment:
   Please add javadoc for this class.



##########
parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/SQLServerStatementVisitor.java:
##########
@@ -1338,4 +1350,99 @@ public ASTNode visitCreateTableAsSelectClause(final CreateTableAsSelectClauseCon
         }
         return result;
     }
+    
+    @Override
+    public ASTNode visitUpdateStatistics(final UpdateStatisticsContext ctx) {
+        SQLServerUpdateStatisticsStatement result = new SQLServerUpdateStatisticsStatement();
+        if (null != ctx.tableName()) {
+            result.setTable((SimpleTableSegment) visit(ctx.tableName()));
+        }
+        if (null != ctx.indexName() && ctx.indexName().size() > 0) {
+            List<IndexSegment> indexSegments = new LinkedList<>();
+            for (IndexNameContext indexNameContext : ctx.indexName()) {
+                indexSegments.add((IndexSegment) visit(indexNameContext));
+            }
+            result.setIndexes(indexSegments);
+        }
+        if (null != ctx.statisticsWithClause()) {
+            result.setStrategy((StatisticsStrategySegment) visit(ctx.statisticsWithClause()));
+        }
+        return result;
+    }
+    
+    @Override
+    public ASTNode visitStatisticsWithClause(final StatisticsWithClauseContext ctx) {
+        StatisticsStrategySegment segment = new StatisticsStrategySegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex());
+        if (null != ctx.sampleOption()) {
+            segment.setSampleOption((SampleOptionSegment) visit(ctx.sampleOption()));
+        }
+        if (null != ctx.statisticsOptions()) {
+            segment.setStatisticsOptions((StatisticsOptionSegment) visit(ctx.statisticsOptions()));
+        }
+        return segment;
+    }
+    
+    @Override
+    public ASTNode visitStatisticsOption(final StatisticsOptionContext ctx) {
+        return super.visitStatisticsOption(ctx);
+    }
+    
+    @Override
+    public ASTNode visitSampleOption(final SampleOptionContext ctx) {
+        SampleOptionSegment segment = new SampleOptionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex());
+        if (null != ctx.FULLSCAN()) {
+            segment.setStrategy(SampleStrategy.FULLSCAN);
+        } else if (null != ctx.SAMPLE()) {
+            segment.setStrategy(SampleStrategy.SAMPLE);
+            if (null != ctx.NUMBER_()) {
+                List<TerminalNode> number = ctx.NUMBER_();
+                segment.setSampleNumber(number.get(0).getText());
+            }
+            if (null != ctx.PERCENT()) {
+                segment.setScanUnit(ScanUnit.PERCENT);
+            } else if (null != ctx.ROWS()) {
+                segment.setScanUnit(ScanUnit.ROWS);
+            }
+        } else if (null != ctx.RESAMPLE()) {
+            segment.setStrategy(SampleStrategy.RESAMPLE);
+            if (null != ctx.NUMBER_()) {
+                List<String> partitions = new LinkedList<>();
+                for (TerminalNode terminalNode : ctx.NUMBER_()) {
+                    partitions.add(terminalNode.getText());
+                }
+                segment.setPartitions(partitions);
+            }
+        }
+        if (null != ctx.PERSIST_SAMPLE_PERCENT()) {
+            segment.setPersistSamplePercent(null != ctx.ON());
+        }
+        return segment;

Review Comment:
   Please rename segment to result.



##########
parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/sqlserver/segment/StatisticsStrategySegment.java:
##########
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+package org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.segment;
+
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.SQLSegment;
+
+@Getter
+@Setter
+@NoArgsConstructor
+public final class StatisticsStrategySegment implements SQLSegment {

Review Comment:
   Please add javadoc for this class.



##########
parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/sqlserver/segment/ScanUnit.java:
##########
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+package org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.segment;
+
+public enum ScanUnit {

Review Comment:
   Please add javadoc for ScanUnit.



##########
parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/sqlserver/segment/StatisticsOptionSegment.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+package org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.segment;
+
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.SQLSegment;
+
+@Getter
+@Setter
+@NoArgsConstructor
+public final class StatisticsOptionSegment implements SQLSegment {

Review Comment:
   Please add javadoc for this class.



##########
parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/sqlserver/segment/SampleStrategy.java:
##########
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+package org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.segment;
+
+public enum SampleStrategy {

Review Comment:
   Please add javadoc for SampleStrategy.



-- 
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