[ 
https://issues.apache.org/jira/browse/PHOENIX-6960?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17764837#comment-17764837
 ] 

ASF GitHub Bot commented on PHOENIX-6960:
-----------------------------------------

virajjasani commented on code in PR #1663:
URL: https://github.com/apache/phoenix/pull/1663#discussion_r1324960871


##########
phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java:
##########
@@ -1691,8 +1691,10 @@ public KeySlots visitLeave(LikeExpression node, 
List<KeySlots> childParts) {
             KeySlots childSlots = childParts.get(0);
             KeySlot childSlot = childSlots.getSlots().get(0);
             final String startsWith = node.getLiteralPrefix();
-            SortOrder sortOrder = node.getChildren().get(0).getSortOrder();
-            byte[] key = PVarchar.INSTANCE.toBytes(startsWith, sortOrder);
+            // TODO: is there a case where we'd need to go through the 
childPart to calculate the key range?
+            PColumn column = childSlot.getKeyPart().getColumn();
+            PDataType type = column.getDataType();
+            byte[] key = PVarchar.INSTANCE.toBytes(startsWith, SortOrder.ASC);

Review Comment:
   interesting! do we support `col1 LIKE ('xy%' || col2)` case? 
   i tried this and saw that we return right here due to empty childParts:
   ```
           @Override
           public KeySlots visitLeave(LikeExpression node, List<KeySlots> 
childParts) {
               // TODO: optimize ILIKE by creating two ranges for the literal 
prefix: one with lower case, one with upper case
               if (childParts.isEmpty()) {
                   return null;
               }
   ...
   ...
   ```





> Scan range is wrong when query desc columns
> -------------------------------------------
>
>                 Key: PHOENIX-6960
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-6960
>             Project: Phoenix
>          Issue Type: Bug
>    Affects Versions: 5.1.3
>            Reporter: fanartoria
>            Assignee: Jing Yu
>            Priority: Critical
>             Fix For: 5.2.0, 5.1.4
>
>
> Ways to reproduce
> {code}
> 0: jdbc:phoenix:> create table sts(id integer primary key, name varchar, type 
> integer, status integer);
> No rows affected (1.259 seconds)
> 0: jdbc:phoenix:> create index sts_name_desc on sts(status, type desc, name 
> desc);
> ^[[ANo rows affected (6.376 seconds)
> 0: jdbc:phoenix:> create index sts_name_asc on sts(type desc, name) include 
> (status);
> No rows affected (6.377 seconds)
> 0: jdbc:phoenix:> upsert into sts values(1, 'test10.txt', 1, 1);
> 1 row affected (0.026 seconds)
> 0: jdbc:phoenix:>
> 0: jdbc:phoenix:>
> 0: jdbc:phoenix:> explain select * from sts where type = 1 and name like 
> 'test10%';
> +------------------------------------------------------------------------------------------------------+----------------+---------------+-------------+
> |                                                 PLAN                        
>                          | EST_BYTES_READ | EST_ROWS_READ | EST_INFO_TS |
> +------------------------------------------------------------------------------------------------------+----------------+---------------+-------------+
> | CLIENT 1-CHUNK PARALLEL 1-WAY ROUND ROBIN RANGE SCAN OVER STS_NAME_ASC 
> [~1,'test10'] - [~1,'test11'] | null           | null          | null        |
> +------------------------------------------------------------------------------------------------------+----------------+---------------+-------------+
> 1 row selected (0.023 seconds)
> 0: jdbc:phoenix:> select * from sts where type = 1 and name like 'test10%';
> +----+------------+------+--------+
> | ID |    NAME    | TYPE | STATUS |
> +----+------------+------+--------+
> | 1  | test10.txt | 1    | 1      |
> +----+------------+------+--------+
> 1 row selected (0.033 seconds)
> 0: jdbc:phoenix:> explain select * from sts where status = 1 and type = 1 and 
> name like 'test10%';
> +-------------------------------------------------------------------------------------------------------------+----------------+---------------+-------------+
> |                                                    PLAN                     
>                                 | EST_BYTES_READ | EST_ROWS_READ | 
> EST_INFO_TS |
> +-------------------------------------------------------------------------------------------------------------+----------------+---------------+-------------+
> | CLIENT 1-CHUNK PARALLEL 1-WAY ROUND ROBIN RANGE SCAN OVER STS_NAME_DESC 
> [1,~1,~'test10'] - [1,~1,~'test1/'] | null           | null          | null   
>      |
> |     SERVER FILTER BY FIRST KEY ONLY AND "NAME" LIKE 'test10%'               
>                                 | null           | null          | null       
>  |
> +-------------------------------------------------------------------------------------------------------------+----------------+---------------+-------------+
> 2 rows selected (0.022 seconds)
> 0: jdbc:phoenix:> select * from sts where status = 1 and type = 1 and name 
> like 'test10%';
> +----+------+------+--------+
> | ID | NAME | TYPE | STATUS |
> +----+------+------+--------+
> +----+------+------+--------+
> No rows selected (0.04 seconds)
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to