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

James Taylor commented on PHOENIX-4476:
---------------------------------------

You'll want to make this change in WhereOptimizer - that's where we have the 
knowledge about columns being PK columns and matching them up against constants 
in the WHERE clause. You should be able to isolate the change to two methods:
{code:java}
        private KeySlots 
newRowValueConstructorKeyParts(RowValueConstructorExpression rvc, 
List<KeySlots> childSlots) {{code}
You'll need to adapt this method to detect if you have all PK columns, but 
they're out of order (i.e. childSlots.size() >= numberOfPKColumns and all PK 
columns are present). Create new state in RowValueConstructorKeyPart that 
remembers this and don't sub list the original RVC (but still remember the 
index at which it would have been sub listed).

Then, in KeyExpressionVisitor.visitLeave(InListExpresssion...) you'll use the 
above information (if the keySlot.getPKSpan() > 1). At that point you can 
reorder the KeyPart expressions to be in PK order (you'll probably need to cast 
KeyPart to RowValueConstructorKeyPart)
{code:java}
        public KeySlots visitLeave(InListExpression node, List<KeySlots> 
childParts) {{code}
Also, you won't know in newRowValueConstructorKeyParts if you're in an IN list 
or in an inequality expression (i.e. (a,b) > (1,2)), If the latter, then you'll 
go through visitLeave(ComparisonExpression node...) and you don't want the 
behavior changed in this case. Note that (a,b) = (1,2) will already have been 
transformed to a=1 and b=2, so you'll never have the case where 
ComparisonExpression is an equality for a RVC.

 

 

> Range scan used for point lookups if filter is not in order of primary keys
> ---------------------------------------------------------------------------
>
>                 Key: PHOENIX-4476
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-4476
>             Project: Phoenix
>          Issue Type: Bug
>    Affects Versions: 4.13.1
>            Reporter: Mujtaba Chohan
>            Assignee: Xu Cang
>            Priority: Major
>              Labels: SFDC
>         Attachments: PHOENIX-4476-4.x-HBase-1.3.002.patch
>
>
> {noformat}
> DROP TABLE TEST;
> CREATE TABLE IF NOT EXISTS TEST (
>     PK1 CHAR(1) NOT NULL,
>     PK2 VARCHAR NOT NULL,
>     PK3 VARCHAR NOT NULL,
>     PK4 UNSIGNED_LONG NOT NULL,
>     PK5 VARCHAR NOT NULL,
>     V1 VARCHAR,
>     V2 VARCHAR,
>     V3 UNSIGNED_LONG
>     CONSTRAINT state_pk PRIMARY KEY (
>           PK1,
>           PK2,
>           PK3,
>           PK4,
>           PK5
>     )
> );
> // Incorrect explain plan with un-ordered PKs
> EXPLAIN SELECT V1 FROM TEST WHERE (PK1, PK5, PK2, PK3, PK4) IN (('A', 'E', 
> 'N', 'T', 3), ('A', 'Y', 'G', 'T', 4)); 
> +------------------------------------------+------------------------------------------+------------------------------------------+---------+
> |                   PLAN                   |              EST_BYTES_READ      
>         |              EST_ROWS_READ               |         |
> +------------------------------------------+------------------------------------------+------------------------------------------+---------+
> | CLIENT 1-CHUNK PARALLEL 1-WAY ROUND ROBIN RANGE SCAN OVER TEST ['A'] | null 
>                                     | null                   |
> |     SERVER FILTER BY (PK1, PK5, PK2, PK3, PK4) IN 
> ([65,69,0,78,0,84,0,0,0,0,0,0,0,0,3],[65,89,0,71,0,84,0,0,0,0,0,0,0,0,4]) | 
> null       |
> +------------------------------------------+------------------------------------------+------------------------------------------+---------+
> // Correct explain plan with PKs in order
> EXPLAIN SELECT V1 FROM TEST WHERE (PK1,PK2,PK3,PK4,PK5) IN (('A', 'E', 'N',3, 
> 'T'),('A', 'Y', 'G', 4, 'T')); 
> +------------------------------------------+------------------------------------------+------------------------------------------+---------+
> |                   PLAN                   |              EST_BYTES_READ      
>         |              EST_ROWS_READ               |         |
> +------------------------------------------+------------------------------------------+------------------------------------------+---------+
> | CLIENT 1-CHUNK 2 ROWS 712 BYTES PARALLEL 1-WAY ROUND ROBIN POINT LOOKUP ON 
> 2 KEYS OVER TEST | 712                                      | |
> +------------------------------------------+------------------------------------------+------------------------------------------+---------+
> {noformat}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to