-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Casting from Binary --> Utf8 to evaluate LIKE
slows down some ClickBench queries
#12509
Comments
I have been thinking about this, and I came up with a third option which is to "push the casting into the scan" Consider this plan for q28:
The
Is what is causing a non trivial slowdown. The issue is that The problem is that BinaryView --> Utf8View conversion is much slower than reading Utf8View directly out of the parquet file due to the Utf8 optimization described by @XiangpengHao in "Section 2.1: From binary to strings" of the string view blog. Option 3: Implement push down casting (maybe as an Analyzer rule??)The theory here is that some readers( such as the parquet reader) can produce the data more effiicently in a particular format than creating it first in one format before datafusion casts it to another. So the plan above would basically push the cast down so the parquet reader read the |
Is your feature request related to a problem or challenge? Please describe what you are trying to do.
While working on enabling
StringView
by default in #12092 I noticed that some of the clickbench queries got 10% slower and looked into it.The plan looks like this:
When looking at the flamegraphs, you can see the
CAST
spends a huge amount of time validating utf8 (more time than actually evaluating theLIKE
predicate actually):Here are the full flamegraphs for comparison:
q20-flamegraph-main
q20-flamegraph-stringview
I belive the issue is here:
This filter first *CAST
s the URL column to Utf8View and then evaluates
LIKE`Converting
BinaryArray
-->StringArray
as is done without StringView is relatively faster because it is done with a single large function callHowever, converting
BinaryViewArrar
-->StringViewArray
is not as it makes many small function calls. The parquet reader has a special optimization for this as descsribed in "Section 2.1: From binary to strings" of the Using StringView / German Style Strings to Make Queries Faster: Part 1 - Reading Parquet from @XiangpengHaoDescribe the solution you'd like
I would like this query to go as fast / faster with Utf8View / BinaryView enabled.
Bonus points if it went faster even without Utf-8 enabled
Describe alternatives you've considered
Option 1:
LIKE
for binaryOne option is to skip validating UTF8 entirely and evaluate
LIKE
directly on binary. This would mean if the column is read as binary we could cast the argument'%google%'
to binary and then evaluateLIKE
directly on the binary column. This would skip validaitng utf8 completelyUnfortunately, it appears that the
like
kernel is only implemented forStringArray
andStringViewArray
at the moment, not BinaryArray: https://docs.rs/arrow-string/53.0.0/src/arrow_string/like.rs.html#110-149Another related option would be to potentially special case the
LIKE
rewite in this case for just prefix / contians / suffix -- in this case rewrite<binary> LIKE <const that starts and ends with '%'
> --><binary> CONTAINS <string>
Option 2: resolve the column as
Utf8
rather thanBinary
For some reason the schema of
hits.parquet
(the single file from ClickBench) has theURL
column (and others) asUtf8
(strings) but thehits_partitioned
file resolves it as Binary. \We could change the schema resolution logicic to resolve the column as a String instead.
This option is probably slower than option 1 but I think it is more inline with what the intended semantics (these columns contain logical stirngs) and the parquet reader includes the fast read path for such strings and would be more general.
Filed #12510 to track this ideae
Additional context
The text was updated successfully, but these errors were encountered: