[SPARK-34251][SQL] Fix table stats calculation by TRUNCATE TABLE#31350
Closed
MaxGekk wants to merge 4 commits intoapache:masterfrom
Closed
[SPARK-34251][SQL] Fix table stats calculation by TRUNCATE TABLE#31350MaxGekk wants to merge 4 commits intoapache:masterfrom
TRUNCATE TABLE#31350MaxGekk wants to merge 4 commits intoapache:masterfrom
Conversation
|
Kubernetes integration test starting |
|
Kubernetes integration test status success |
Member
Author
|
@dongjoon-hyun @sunchao @cloud-fan @HyukjinKwon Could you review this fix, please. |
cloud-fan
approved these changes
Jan 27, 2021
Contributor
|
thanks, merging to master! |
skestle
pushed a commit
to skestle/spark
that referenced
this pull request
Feb 3, 2021
### What changes were proposed in this pull request? 1. Take into account the SQL config `spark.sql.statistics.size.autoUpdate.enabled` in the `TRUNCATE TABLE` command as other commands do. 2. Re-calculate actual table size in fs. Before the changes, `TRUNCATE TABLE` always sets table size to 0 in stats. ### Why are the changes needed? This fixes the bug that is demonstrated by the example: 1. Create a partitioned table with 2 non-empty partitions: ```sql spark-sql> CREATE TABLE tbl (c0 int, part int) PARTITIONED BY (part); spark-sql> INSERT INTO tbl PARTITION (part=0) SELECT 0; spark-sql> INSERT INTO tbl PARTITION (part=1) SELECT 1; spark-sql> ANALYZE TABLE tbl COMPUTE STATISTICS; spark-sql> DESCRIBE TABLE EXTENDED tbl; ... Statistics 4 bytes, 2 rows ... ``` 2. Truncate only one partition: ```sql spark-sql> TRUNCATE TABLE tbl PARTITION (part=1); spark-sql> SELECT * FROM tbl; 0 0 ``` 3. The table is still non-empty but `TRUNCATE TABLE` reseted stats: ``` spark-sql> DESCRIBE TABLE EXTENDED tbl; ... Statistics 0 bytes, 0 rows ... ``` ### Does this PR introduce _any_ user-facing change? It could impact on performance of following queries. ### How was this patch tested? Added new test to `StatisticsCollectionSuite`: ``` $ build/sbt -Phive -Phive-thriftserver "test:testOnly *StatisticsCollectionSuite" $ build/sbt -Phive -Phive-thriftserver "test:testOnly *StatisticsSuite" ``` Closes apache#31350 from MaxGekk/fix-stats-in-trunc-table. Authored-by: Max Gekk <max.gekk@gmail.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
spark.sql.statistics.size.autoUpdate.enabledin theTRUNCATE TABLEcommand as other commands do.TRUNCATE TABLEalways sets table size to 0 in stats.Why are the changes needed?
This fixes the bug that is demonstrated by the example:
TRUNCATE TABLEreseted stats:Does this PR introduce any user-facing change?
It could impact on performance of following queries.
How was this patch tested?
Added new test to
StatisticsCollectionSuite: