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

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

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


##########
phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java:
##########
@@ -1722,7 +1725,10 @@ public KeySlots visitLeave(LikeExpression node, 
List<KeySlots> childParts) {
                 lowerRange = Arrays.copyOf(lowerRange, lowerRange.length+1);
                 lowerRange[lowerRange.length-1] = 
QueryConstants.SEPARATOR_BYTE;
             }
-            KeyRange range = type.getKeyRange(lowerRange, true, upperRange, 
false, SortOrder.ASC);
+            boolean lowerInclusive = column.getSortOrder() == SortOrder.ASC;
+            boolean upperInclusive = column.getSortOrder() == SortOrder.DESC;
+            KeyRange range = type.getKeyRange(lowerRange, lowerInclusive, 
upperRange,
+                    upperInclusive, SortOrder.ASC);

Review Comment:
   I have debugged into this, and after inverting twice, we end up returning a 
non-inverted range, which eventually gets inverted in 
WhereOptimizer.pushKeyExpressionsToScan().
   
   Do we even need to take SortOrder into account here, and if yes, couldn't we 
simplify this logic ?





> 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