You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One reason for so many downcast_value call is because the grouping column l_partkey is with high cardinality, causing the vectorization is almost useless.
The most expensive part is the line let values = &cast(values, sum_type)? in sum_batch which performs this casting.
I guess we should move that evaluation (or other parts of sum_batch as well) up, so it will be done before the grouping, rather than after, so it still is vectorized.
Another observation I have is that the plan does some unnecessary casting:
@Dandandan , Yes, I also notice this problem, it's related with type coercion.
It isn't a easy problem, type coercion in pg is a top down process, so top can request type from children.
It's similar with interesting order/enforcement. But current datafusion do type coercion like mysql bottom up, it isn't good enough.
I prepare to improve type coercion in the future according to PG and Spark.
BTW, #5831 also is related with this q17, it move cast from expression eval into subplan.
@Dandandan specially when using their native format, Hyper just literally don't care about RAM, i use it with the free colab, and did finish tpch_sf110 !!! just fine, what do you think they are doing different ?
@Dandandan specially when using their native format, Hyper just literally don't care about RAM, i use it with the free colab, and did finish tpch_sf110 !!! just fine, what do you think they are doing different ?
Hard to say in general, but they do some optimizations we don't do or do better planning (e.g. for join selection).
Using a different format instead of parquet might help as well as parquet can be slower to decode / decompress than formats optimized for query performance.
!! just fine, what do you think they are doing different ?
It is also probably good to point out that hyper is largely a research system and one of the standard benchmark sets that is used for research systems is TPCH
Thus I suspect a lot of effort has gone into making the patterns that appear in TPCH very fast (e.g. left deep join trees with very selective predicates). That is not to say that the optimizations are entirely TPCH specific, but it wouldn't surprise me if in general purpose use DataFusion performance much closer (or better)
!! just fine, what do you think they are doing different ?
It is also probably good to point out that hyper is largely a research system and one of the standard benchmark sets that is used for research systems is TPCH
Thus I suspect a lot of effort has gone into making the patterns that appear in TPCH very fast (e.g. left deep join trees with very selective predicates). That is not to say that the optimizations are entirely TPCH specific, but it wouldn't surprise me if in general purpose use DataFusion performance much closer (or better)
Hyper-db is developed by Tableau now, so it probably has some improvements over the last years compared to the "research system":
Some release notes for last couple of years: https://tableau.github.io/hyper-db/docs/releases
Given the long history of this issue, I think it is hard to understand what, if anything, it is tracking. I suggest we close it and file another issue to continue discussing additional performance improvements
Btw, DF31 is making a great progress, my impression as long as the data fit in memory, the performance is very similar to DuckDB, here I am reading Parquet files from an Azure storage, the main issue start with core 8 which has 64 of GB, Query 18 crash the notebook
BTW I think the core problem here is that DataFusion's parallel hash grouping builds the entire hash table for each input partition -- thus it requires memory proportional to the number of cores. This is tracked more in #6937
I spent some time analyzing why Q17 and Q18 are slow in detail this morning (in the context of #6782 ). My analysis shows we could close most of the gap with a better join order:
The issue seems to be (at least partially) related to FilterExec returning unknown statistics in case of unsupported filter predicates -- I wonder, if it would be better / more correct to rely on worth-case scenario for such filters, and simply propagate input statistics -- it seems to be enough to fix Q17 plan.
I wonder, if it would be better / more correct to rely on worth-case scenario for such filters, and simply propagate input statistics
Perhaps the filter can simply switch to Precision::Inexact when it can't analyze the selectivity for the expression
Another thing I have seen in the past is heuristically pick a constant selectivity (assume it filters 1/2 the rows). However I think this leads to non-robust plans (sometimes the plans are good, sometimes they are bad, and it is hard to predict when each is hit)
Activity
mingmwang commentedon Mar 20, 2023
I will take a look.
mingmwang commentedon Mar 27, 2023
Working on it now. I am not sure whether it is regression or those two queries are always slow.
mingmwang commentedon Mar 29, 2023
The bottle neck of q17 should be Aggregation.
Dandandan commentedon Apr 3, 2023
A profile run using flamegraph shows on my machine:
arrow_cast::cast::cast_decimal_to_decimalis consuming about 1/4 of the time of q17.Dandandan commentedon Apr 3, 2023
Dandandan commentedon Apr 3, 2023
FYI @viirya
mingmwang commentedon Apr 4, 2023
One reason for so many
downcast_valuecall is because the grouping columnl_partkeyis with high cardinality, causing the vectorization is almost useless.Dandandan commentedon Apr 4, 2023
The most expensive part is the line
let values = &cast(values, sum_type)?insum_batchwhich performs this casting.I guess we should move that evaluation (or other parts of
sum_batchas well) up, so it will be done before the grouping, rather than after, so it still is vectorized.Dandandan commentedon Apr 4, 2023
Another observation I have is that the plan does some unnecessary casting:
sum_batch)__scalar_sq_3.__value. I guess because 0.2 is assumed to be a float.mingmwang commentedon Apr 4, 2023
@Dandandan
#5866
jackwener commentedon Apr 5, 2023
@Dandandan , Yes, I also notice this problem, it's related with
type coercion.It isn't a easy problem,
type coercionin pg is atop downprocess, so top can request type from children.It's similar with
interesting order/enforcement. But current datafusion dotype coercionlike mysqlbottom up, it isn't good enough.I prepare to improve type coercion in the future according to PG and Spark.
BTW, #5831 also is related with this q17, it move cast from expression eval into subplan.
Dandandan commentedon Apr 5, 2023
@jackwener Nice, thank you
Dandandan commentedon Jun 19, 2023
@jackwener this is all resolved now, right?
djouallah commentedon Jun 20, 2023
datafusion is doing a great progress but still, it is not solved
Version: 26.0.0
17 remaining items
djouallah commentedon Aug 3, 2023
@Dandandan specially when using their native format, Hyper just literally don't care about RAM, i use it with the free colab, and did finish tpch_sf110 !!! just fine, what do you think they are doing different ?
Dandandan commentedon Aug 3, 2023
Hard to say in general, but they do some optimizations we don't do or do better planning (e.g. for join selection).
Using a different format instead of parquet might help as well as parquet can be slower to decode / decompress than formats optimized for query performance.
alamb commentedon Aug 3, 2023
It is also probably good to point out that hyper is largely a research system and one of the standard benchmark sets that is used for research systems is TPCH
Thus I suspect a lot of effort has gone into making the patterns that appear in TPCH very fast (e.g. left deep join trees with very selective predicates). That is not to say that the optimizations are entirely TPCH specific, but it wouldn't surprise me if in general purpose use DataFusion performance much closer (or better)
Dandandan commentedon Aug 4, 2023
Hyper-db is developed by Tableau now, so it probably has some improvements over the last years compared to the "research system":
Some release notes for last couple of years: https://tableau.github.io/hyper-db/docs/releases
djouallah commentedon Sep 14, 2023
it seems there is a regression with query 18, it used to works fine with tpch100 using 124 GB of RAM, now the notebook crashes when using DF31 !!!
edit : never mind, it was a temporary glitch,
alamb commentedon Sep 19, 2023
Given the long history of this issue, I think it is hard to understand what, if anything, it is tracking. I suggest we close it and file another issue to continue discussing additional performance improvements
djouallah commentedon Sep 19, 2023
the issue is very clear, performance of Query 17 and 18 is still very slow compared to other in process engines !!

djouallah commentedon Sep 20, 2023
Btw, DF31 is making a great progress, my impression as long as the data fit in memory, the performance is very similar to DuckDB, here I am reading Parquet files from an Azure storage, the main issue start with core 8 which has 64 of GB, Query 18 crash the notebook

alamb commentedon Oct 17, 2023
BTW I think the core problem here is that DataFusion's parallel hash grouping builds the entire hash table for each input partition -- thus it requires memory proportional to the number of cores. This is tracked more in #6937
alamb commentedon Oct 27, 2023
I spent some time analyzing why
Q17andQ18are slow in detail this morning (in the context of #6782 ). My analysis shows we could close most of the gap with a better join order:korowa commentedon Nov 6, 2023
The issue seems to be (at least partially) related to
FilterExecreturning unknown statistics in case of unsupported filter predicates -- I wonder, if it would be better / more correct to rely on worth-case scenario for such filters, and simply propagate input statistics -- it seems to be enough to fix Q17 plan.alamb commentedon Nov 6, 2023
Perhaps the filter can simply switch to
Precision::Inexactwhen it can't analyze the selectivity for the expressionAnother thing I have seen in the past is heuristically pick a constant selectivity (assume it filters 1/2 the rows). However I think this leads to non-robust plans (sometimes the plans are good, sometimes they are bad, and it is hard to predict when each is hit)
alamb commentedon Nov 7, 2023
I filed #8078 with a proposal of a more precise way to represent inexact statistics
djouallah commentedon Nov 16, 2023
Thank you very much for your works, I am happy with datafusion 33 performance, now it does finish TPCH_SF100 using 64 GB of RAM in Fabric