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
{{ message }}
Repository navigation
Allow sorting to improve FixedSizeBinary filtering聽#11170
Is it a bug? Is it a feature? No one has every really known 馃し .
We have an ID field which is really a u128, because arrow doesn't support u128, I experimented with making it a DataType::FixedSizeBinary(16) instead of a string.
The performance differences when querying the column (just looking for a single row that matched a value) were quite surprising to me (updated, see below):
unsorted string: 600ms
unsorted FWB: 350ms
sorted string: 56ms
sorted FWB: 350ms
("FWB" == FixedSizeBinary(16))
I assume the point is that FixedSizeBinary doesn't support using the known sort order to improve filtering?
I assume (probably naively) that this shouldn't be too hard to add. Where would I start looking to add it?
In parquet to query with datafusion, and wanted it to be fast long term, what would you use?
I would have recommended using FixedSizeBinary as you have done (and in fact I believe @hiltontj is doing something like this internall at InfluxData at the moment).
However I got broadly similar numbers to you in with the different types (and I agree Decimal128 looks quite good)
What's weird is the behaviour with a decimal 128 is better than a uint64 when sorted. Is that that a fundamental side affect of the type, or some missing logic/optimisation?
What's weird is the behaviour with a decimal 128 is better than a uint64 when sorted. Is that that a fundamental side affect of the type, or some missing logic/optimisation?
I suspect it is some missing optimization -- I don't know of any reason that fixed size binary would be less efficient than decimal.
I double checked that FixedSizeBinary is also stored inline
I think the problem is that herearrow-rs has special cases for primative types and "byte types" e.g. strings, but no special case for FixedSizeBinary. Not sure how much of the slow down is due to that, but could be significant.
I think the problem is that herearrow-rs has special cases for primative types and "byte types" e.g. strings, but no special case for FixedSizeBinary. Not sure how much of the slow down is due to that, but could be significant.
This is what I observed: 98% of the time was spent on reading data from parquet files and 1.2% of the time was spent on querying (see screenshot below). So it is hard to tell whether the unsorted FixSizeBinary is slower or not with the current example code.
This is what I observed: 98% of the time was spent on reading data from parquet files and 1.2% of the time was spent on querying (see screenshot below). So it is hard to tell whether the unsorted FixSizeBinary is slower or not with the current example code. Maybe other people can try a different approach to measure where the time was spent
I might be misreading the profile but that has 90% of the time in the byte_array_reader compared to only 0.6% of the time in the fixed_len_byte_array_reader?
Activity
samuelcolvin commentedon Jun 29, 2024
Well that's embarrassing 馃う, I forgot
--release.In release mode:
Kind of even more surprising - Surely FWB should be faster as you don't need to calculate offsets?
samuelcolvin commentedon Jun 29, 2024
Well it keeps getting weirder.
In release mode:
(Trying
UInt64was the first step towards using a struct of twoUInt64, but it seems unlike that would be as fast as a string right now)This is all very confusing.
TL;DR; - @alamb if you were storing
In parquet to query with datafusion, and wanted it to be fast long term, what would you use?
samuelcolvin commentedon Jun 29, 2024
Okay last comment here (for now), I'll stop talking to myself.
It seems that
Decimal128is the best option for our case (we can rewrite it to look like hex and be queried with hex):Times
(unsorted, sorted):DataType::FixedSizeBinary(16) - (51, 57)DataType::LargeUtf8 - (81, 10)DataType::UInt64 - (52, 36)DataType::Decimal128(38, 10) - (57, 7)alamb commentedon Jun 30, 2024
I would have recommended using
FixedSizeBinaryas you have done (and in fact I believe @hiltontj is doing something like this internall at InfluxData at the moment).However I got broadly similar numbers to you in with the different types (and I agree Decimal128 looks quite good)
I checked out https://github.com/samuelcolvin/datafusion-id-experiment and got an explain plan with metrics (ran
EXPLAIN ANALYZE {sql}):FixedSizeBinary
Decimal
I don't really have great insight as to why Decimal was better -- it may be because it is stored inline as
i128values (rather than out of line).samuelcolvin commentedon Jun 30, 2024
What's weird is the behaviour with a decimal 128 is better than a uint64 when sorted. Is that that a fundamental side affect of the type, or some missing logic/optimisation?
alamb commentedon Jul 1, 2024
I suspect it is some missing optimization -- I don't know of any reason that fixed size binary would be less efficient than decimal.
I double checked that FixedSizeBinary is also stored inline
samuelcolvin commentedon Jul 26, 2024
I think the problem is that here
arrow-rshas special cases for primative types and "byte types" e.g. strings, but no special case forFixedSizeBinary. Not sure how much of the slow down is due to that, but could be significant.alamb commentedon Jul 29, 2024
Thank you @samuelcolvin -- filed apache/arrow-rs#6153 to track
appletreeisyellow commentedon Aug 7, 2024
Hi @samuelcolvin! I'm playing around your example code samuelcolvin/datafusion-id-experiment on my Mac M1 and I got empty results for all the queries.
Click to see what I did and what I got
cargo build --release./target/release/union-scratchIs this what is expected? Anything did I miss?
appletreeisyellow commentedon Aug 8, 2024
I was trying to see where the time was spent for
FixedSizeBinary, so I used Mac's Instrument CPU Profiler to run a CPU profiling on the benchmark / example code: samuelcolvin/datafusion-id-experimentThis is what I observed: 98% of the time was spent on reading data from parquet files and 1.2% of the time was spent on querying (see screenshot below). So it is hard to tell whether the unsorted
FixSizeBinaryis slower or not with the current example code.appletreeisyellow commentedon Aug 8, 2024
I was trying to see where the time was spent for
FixedSizeBinary, so I used Mac's Instrument CPU Profiler to run a CPU profiling on the benchmark / example code: samuelcolvin/datafusion-id-experimentThis is what I observed: 98% of the time was spent on reading data from parquet files and 1.2% of the time was spent on querying (see screenshot below). So it is hard to tell whether the unsorted
FixSizeBinaryis slower or not with the current example code. Maybe other people can try a different approach to measure where the time was spentalamb commentedon Aug 9, 2024
Thanks @appletreeisyellow -- I filed apache/arrow-rs#6219 upstream to track the idea of making this faster
tustvold commentedon Aug 9, 2024
I might be misreading the profile but that has 90% of the time in the byte_array_reader compared to only 0.6% of the time in the fixed_len_byte_array_reader?
adriangb commentedon Mar 3, 2025
I think we can close this since apache/arrow-rs#6219 is resolved?
samuelcolvin commentedon Mar 4, 2025
Closed