Re: [I] Slow comparisions to dictionary columns with type coercion [datafusion]

2024-05-01 Thread via GitHub


alamb closed issue #10220: Slow comparisions to dictionary columns with type 
coercion
URL: https://github.com/apache/datafusion/issues/10220


-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org



Re: [I] Slow comparisions to dictionary columns with type coercion [datafusion]

2024-04-30 Thread via GitHub


alamb commented on issue #10220:
URL: https://github.com/apache/datafusion/issues/10220#issuecomment-2087629144

   Thanks @erratic-pattern  -- I hope to look at this tomorrow morning


-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org



Re: [I] Slow comparisions to dictionary columns with type coercion [datafusion]

2024-04-30 Thread via GitHub


erratic-pattern commented on issue #10220:
URL: https://github.com/apache/datafusion/issues/10220#issuecomment-2087570905

   https://github.com/apache/datafusion/pull/10323 is ready for review and 
avoids the previously discussed issues with 
https://github.com/apache/datafusion/pull/10221 


-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org



Re: [I] Slow comparisions to dictionary columns with type coercion [datafusion]

2024-04-24 Thread via GitHub


erratic-pattern commented on issue #10220:
URL: https://github.com/apache/datafusion/issues/10220#issuecomment-2075811286

   I have a PR that fixes this. Here is the explain after making the change:
   
   ```
   > explain SELECT * from test where column1 = 1;
   +---+-+
   | plan_type | plan|
   +---+-+
   | logical_plan  | Filter: test.column1 = Dictionary(Int32, Utf8("1")) |
   |   |   TableScan: test projection=[column1]  |
   | physical_plan | CoalesceBatchesExec: target_batch_size=8192 |
   |   |   FilterExec: column1@0 = 1 |
   |   | MemoryExec: partitions=1, partition_sizes=[1]   |
   |   | |
   +---+-+
   2 row(s) fetched.
   Elapsed 0.008 seconds.
   ```
   
   However it looks like some tests are failing so I am still looking into it.


-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org



[I] Slow comparisions to dictionary columns with type coercion [datafusion]

2024-04-24 Thread via GitHub


alamb opened a new issue, #10220:
URL: https://github.com/apache/datafusion/issues/10220

   ### Is your feature request related to a problem or challenge?
   
   In InfluxDB we use `Dictionary(Int32, Utf8)` columns a lot.
   
   Queries like this (with string constants) work great and are very fast
   ```sql
   SELECT ... WHERE column = '1'
   ```
   
   Queries like this (note `1` is an integer, not a `'1'`) the query goes very 
slow
   
   ```sql
   SELECT ... WHERE column = 1
   ```
   
   @erratic-pattern  and I tracked this down to an issue/ limitation in type 
coercion:
   
   ## Reproducer
   
   ```
   DataFusion CLI v37.1.0
   > create table test as values (arrow_cast('1', 'Dictionary(Int32, Utf8)'));
   0 row(s) fetched.
   Elapsed 0.010 seconds.
   
   > select arrow_typeof(column1) from test;
   ++
   | arrow_typeof(test.column1) |
   ++
   | Dictionary(Int32, Utf8)|
   ++
   1 row(s) fetched.
   Elapsed 0.002 seconds.
   
   > explain SELECT * from test where column1 = 1;
   +---+---+
   | plan_type | plan  |
   +---+---+
   | logical_plan  | Filter: CAST(test.column1 AS Utf8) = Utf8("1")|
   |   |   TableScan: test projection=[column1]|
   | physical_plan | CoalesceBatchesExec: target_batch_size=8192   |
   |   |   FilterExec: CAST(column1@0 AS Utf8) = 1 |
   |   | MemoryExec: partitions=1, partition_sizes=[1] |
   |   |   |
   +---+---+
   2 row(s) fetched.
   Elapsed 0.003 seconds.
   ```
   
   
   I think this shows the core problem:
   ```
   | logical_plan  | Filter: CAST(test.column1 AS Utf8) = Utf8("1")|
   ```
   
   It basically shows the column is being converted to a string, rather than 
the constant being converted to th ecorrect type. 
   
   Not only does this mean the column is being un-encoded for the comparsion, 
it also means that `PruningPredicate` doesn't work either
   
   
   
   ### Describe the solution you'd like
   
   I would like the query to go fast lol
   
   Specifically, I think the filter should look like this (no cast on the 
column, and instead the constant type matches)
   
   ```
   | logical_plan  | Filter: test.column1 = Dictionary(Int32, Utf8("1")) |
   ```
   
   
   Note this is what happens if you compare the dictionary column to a string 
literal (
   
   ```sql
   
   > explain SELECT * from test where column1 = '1';
   +---+-+
   | plan_type | plan|
   +---+-+
   | logical_plan  | Filter: test.column1 = Dictionary(Int32, Utf8("1")) |
   |   |   TableScan: test projection=[column1]  |
   | physical_plan | CoalesceBatchesExec: target_batch_size=8192 |
   |   |   FilterExec: column1@0 = 1 |
   |   | MemoryExec: partitions=1, partition_sizes=[1]   |
   |   | |
   +---+-+
   2 row(s) fetched.
   Elapsed 0.002 seconds.
   
   >
   ```
   
   ### Describe alternatives you've considered
   
   _No response_
   
   ### Additional context
   
   _No response_


-- 
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: github-unsubscr...@datafusion.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org