[jira] [Updated] (PHOENIX-5753) Fix erroneous query result when RVC is clipped with desc column

2020-02-29 Thread chenglei (Jira)


 [ 
https://issues.apache.org/jira/browse/PHOENIX-5753?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

chenglei updated PHOENIX-5753:
--
Attachment: PHOENIX-5753_v1-4.x-HBase-1.4.patch

> Fix erroneous query result when RVC is clipped with desc column
> ---
>
> Key: PHOENIX-5753
> URL: https://issues.apache.org/jira/browse/PHOENIX-5753
> Project: Phoenix
>  Issue Type: Bug
>Affects Versions: 5.0.0, 4.15.0
>Reporter: chenglei
>Assignee: chenglei
>Priority: Major
>  Labels: DESC
> Fix For: 4.16.0
>
> Attachments: PHOENIX-5753_v1-4.x-HBase-1.4.patch
>
>
> Given following table and data:
> {code:java}
>CREATE TABLE  test
>(
> pk1 INTEGER NOT NULL ,  
> pk2 INTEGER NOT NULL, 
> pk3 INTEGER NOT NULL, 
> pk4 INTEGER NOT NULL, 
> v INTEGER, CONSTRAINT PK PRIMARY KEY(pk1,pk2,pk3 desc,pk4))
>)
> {code}
>   Noticed pk3 is DESC.
> {code:java}
>UPSERT INTO test (pk1, pk2, pk3, pk4, v) VALUES (1,3,4,10,1)
> {code}
> If we execute the following sql:
> {code:java}
>  select * from test
>  where (pk1 >=1 and pk1<=2) and (pk2>=3 and pk2<=4) and (pk3,pk4) < (5,7)
> {code}
> the returned result is empty, but obviously, the above inserted row 
> (1,3,4,10,1) should be returned.
> I think this problem is introduced by PHOENIX-3383 and PHOENIX-4841, when we 
> clip the {{(pk3,pk4) < (5,7)}} because {{pk3}} is {{DESC}}  by following line 
> 260 in {{WhereOptimizer.pushKeyExpressionsToScan}} , {{(pk3,pk4) < (5,7)}} is 
> clipped to {{pk3 <= 5}} and {{pk4 < 7}} .
> {code:java}
> 257List leftRanges = clipLeft(schema, 
> slot.getPKPosition()
> 258+ slotOffset - clipLeftSpan, clipLeftSpan, 
> keyRanges, ptr);
> 259keyRanges =
> 260clipRight(schema, slot.getPKPosition() + 
> slotOffset - 1, keyRanges,
> 261leftRanges, ptr);
> 262if (prevSortOrder == SortOrder.DESC) {
> 263leftRanges = invertKeyRanges(leftRanges);
> 264}
> 265slotSpanArray[cnf.size()] = clipLeftSpan-1;
> 266cnf.add(leftRanges);
> 267clipLeftSpan = 0;
> 268prevSortOrder = sortOrder;
> 269// since we have to clip the portion with the same 
> sort order, we can no longer
> 270// extract the nodes from the where clause
> 271// for eg. for the schema A VARCHAR DESC, B VARCHAR 
> ASC and query
> 272//   WHERE (A,B) < ('a','b')
> 273// the range (* - a\xFFb) is converted to (~a-*)(*-b)
> 274// so we still need to filter on A,B
> 275stopExtracting = true;
> 276}
> {code}
> Eventually after we completed the  
> {{WhereOptimizer.pushKeyExpressionsToScan}}, the result
> {{ScanRanges.ranges}} is  [[[1 - 2]], [[3 - 4]], [[~5 - *)], [(* - 7)]],  
> {{ScanRanges.useSkipScanFilter}} is {{true}}  and {{SkipScanFilter}} is also 
> [[[1 - 2]], [[3 - 4]], [[~5 - *)], [(* - 7)]], so the  the above inserted row 
> (1,3,4,10,1) could not be retrieved.
> But as we know, {{(pk3,pk4) < (5,7)}} is not semantically equals to {{pk3 <= 
> 5}} and {{pk4 < 7}} , we could only have
>   {{pk3 <= 5}}  but not  {{pk4 < 7}}, so when we clipped  {{(pk3,pk4) < 
> (5,7)}}  to {{pk3 <= 5}} , we could  simply skip remaining columns of this 
> RVC.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Updated] (PHOENIX-5496) Ensure that we handle all server-side mutation codes on the client

2020-02-29 Thread Neha Gupta (Jira)


 [ 
https://issues.apache.org/jira/browse/PHOENIX-5496?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Neha Gupta updated PHOENIX-5496:

Attachment: PHOENIX-5496.master.v1.patch

> Ensure that we handle all server-side mutation codes on the client
> --
>
> Key: PHOENIX-5496
> URL: https://issues.apache.org/jira/browse/PHOENIX-5496
> Project: Phoenix
>  Issue Type: Bug
>Affects Versions: 4.15.0, 5.1.0
>Reporter: Chinmay Kulkarni
>Assignee: Neha Gupta
>Priority: Major
> Fix For: 4.15.1, 5.1.1
>
> Attachments: PHOENIX-5496.4.x-HBase-1.3.patch, 
> PHOENIX-5496.4.x-HBase-1.3.v1.patch, PHOENIX-5496.master.patch, 
> PHOENIX-5496.master.v1.patch, PHOENIX-5496.patch, PHOENIX-5496.v1.patch, 
> PHOENIX-5496.v2.patch, PHOENIX-5496.v3.patch
>
>  Time Spent: 4h
>  Remaining Estimate: 0h
>
> There are many instances throughout wherein we set a certain error mutation 
> code in the RPC callback, however we do not handle these mutation codes on 
> the client.
> For example: 
> If the metadata rows for a tableKey are no longer in that SYSCAT region, 
> checkTableKeyInRegion() fails, the metadata for this table is not written to 
> SYSCAT and [the TABLE_NOT_IN_REGION mutation code is 
> set|https://github.com/apache/phoenix/blob/11997d48d1957cf613526f01c5ccbe2812cf095d/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java#L1785-L1790].
> This is handled for 1 retry inside 
> [CQSI.metaDataCoprocessorExec|https://github.com/apache/phoenix/blob/11997d48d1957cf613526f01c5ccbe2812cf095d/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java#L1568-L1570],
>  but if this happens again, it is returned back to the client where it goes 
> to the default case and succeeds.
> Apart from the fact that partial metadata updates are possible leading to 
> orphan metadata rows in system tables, this also wrongly returns success for 
> clients even though there is no record of that table/view being created 
> inside Phoenix's system tables.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Updated] (PHOENIX-5496) Ensure that we handle all server-side mutation codes on the client

2020-02-29 Thread Neha Gupta (Jira)


 [ 
https://issues.apache.org/jira/browse/PHOENIX-5496?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Neha Gupta updated PHOENIX-5496:

Attachment: (was: PHOENIX-5496.master.v1.patch)

> Ensure that we handle all server-side mutation codes on the client
> --
>
> Key: PHOENIX-5496
> URL: https://issues.apache.org/jira/browse/PHOENIX-5496
> Project: Phoenix
>  Issue Type: Bug
>Affects Versions: 4.15.0, 5.1.0
>Reporter: Chinmay Kulkarni
>Assignee: Neha Gupta
>Priority: Major
> Fix For: 4.15.1, 5.1.1
>
> Attachments: PHOENIX-5496.4.x-HBase-1.3.patch, 
> PHOENIX-5496.4.x-HBase-1.3.v1.patch, PHOENIX-5496.master.patch, 
> PHOENIX-5496.master.v1.patch, PHOENIX-5496.patch, PHOENIX-5496.v1.patch, 
> PHOENIX-5496.v2.patch, PHOENIX-5496.v3.patch
>
>  Time Spent: 4h
>  Remaining Estimate: 0h
>
> There are many instances throughout wherein we set a certain error mutation 
> code in the RPC callback, however we do not handle these mutation codes on 
> the client.
> For example: 
> If the metadata rows for a tableKey are no longer in that SYSCAT region, 
> checkTableKeyInRegion() fails, the metadata for this table is not written to 
> SYSCAT and [the TABLE_NOT_IN_REGION mutation code is 
> set|https://github.com/apache/phoenix/blob/11997d48d1957cf613526f01c5ccbe2812cf095d/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java#L1785-L1790].
> This is handled for 1 retry inside 
> [CQSI.metaDataCoprocessorExec|https://github.com/apache/phoenix/blob/11997d48d1957cf613526f01c5ccbe2812cf095d/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java#L1568-L1570],
>  but if this happens again, it is returned back to the client where it goes 
> to the default case and succeeds.
> Apart from the fact that partial metadata updates are possible leading to 
> orphan metadata rows in system tables, this also wrongly returns success for 
> clients even though there is no record of that table/view being created 
> inside Phoenix's system tables.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Updated] (PHOENIX-5698) Phoenix Query with RVC IN list expression generates wrong scan with non-pk ordered pks

2020-02-29 Thread Xinyi Yan (Jira)


 [ 
https://issues.apache.org/jira/browse/PHOENIX-5698?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Xinyi Yan updated PHOENIX-5698:
---
Attachment: PHOENIX-5698-4.x-HBase-1.3.patch

> Phoenix Query with RVC IN list expression generates wrong scan with non-pk 
> ordered pks
> --
>
> Key: PHOENIX-5698
> URL: https://issues.apache.org/jira/browse/PHOENIX-5698
> Project: Phoenix
>  Issue Type: Bug
>Affects Versions: 4.15.0, 4.14.3
>Reporter: Daniel Wong
>Assignee: Xinyi Yan
>Priority: Major
>  Labels: DESC
> Attachments: PHOENIX-5698-4.14-HBase-1.3.patch, 
> PHOENIX-5698-4.x-HBase-1.3.patch, PHOENIX-5698.patch
>
>  Time Spent: 4h 40m
>  Remaining Estimate: 0h
>
> In the code below ideally we'd expect a SINGLE ROW DELETE plan client side. 
> However, this generates an incorrect scan with range ['tenant1
> 0CY005xx01Sv6o'). If the order of the RVCs is changed to row key order 
> Phoenix correctly generates a SINGLE ROW SCAN.  As we provide the full PK 
> this we expect a either tightly bounded range scan or a client side delete.  
> Instead we get a range scan on composite leading edge 
> TENANT_ID,KEY_PREFIX,ID1.
>  
> {code:java}
> @Test
>  public void testInListExpressionWithDescAgain() throws Exception {
>  String fullTableName = generateUniqueName();
>  String fullViewName = generateUniqueName();
>  String tenantView = generateUniqueName();
>  // create base table and global view using global connection
>  try (Connection conn = DriverManager.getConnection(getUrl()))
> { conn.setAutoCommit(true); Statement stmt = conn.createStatement(); 
> stmt.execute("CREATE TABLE " + fullTableName + "(\n" + " TENANT_ID CHAR(15) 
> NOT NULL,\n" + " KEY_PREFIX CHAR(3) NOT NULL,\n" + " CONSTRAINT PK PRIMARY 
> KEY (\n" + " TENANT_ID," + " KEY_PREFIX" + ")) MULTI_TENANT=TRUE"); 
> stmt.execute("CREATE VIEW " + fullViewName + "(\n" + " ID1 VARCHAR NOT 
> NULL,\n" + " ID2 VARCHAR NOT NULL,\n" + " EVENT_DATE DATE NOT NULL,\n" + " 
> CONSTRAINT PKVIEW PRIMARY KEY\n" + " (\n" + " ID1, ID2 DESC, EVENT_DATE 
> DESC\n" + ")) AS SELECT * FROM " + fullTableName + " WHERE KEY_PREFIX = 
> '0CY'"); }
> // create and use a tenant specific view to write data
>  try (Connection viewConn = DriverManager.getConnection(TENANT_SPECIFIC_URL1) 
> ) {
>  viewConn.setAutoCommit(true); //need autocommit for serverside deletion
>  Statement stmt = viewConn.createStatement();
>  stmt.execute("CREATE VIEW IF NOT EXISTS " + tenantView + " AS SELECT * FROM 
> " + fullViewName );
>  viewConn.createStatement().execute("UPSERT INTO " + tenantView + "(ID1, ID2, 
> EVENT_DATE) VALUES ('005xx01Sv6o', '300', 153245823)");
>  viewConn.createStatement().execute("UPSERT INTO " + tenantView + "(ID1, ID2, 
> EVENT_DATE) VALUES ('005xx01Sv6o', '400', 153245824)");
>  viewConn.createStatement().execute("UPSERT INTO " + tenantView + "(ID1, ID2, 
> EVENT_DATE) VALUES ('005xx01Sv6o', '500', 153245825)");
>  viewConn.commit();
> ResultSet rs = stmt.executeQuery("SELECT ID1, ID2, EVENT_DATE FROM " + 
> tenantView );
>  printResultSet(rs);
> System.out.println("Delete Start");
> rs = stmt.executeQuery("EXPLAIN DELETE FROM " + tenantView + " WHERE (ID1, 
> EVENT_DATE, ID2) IN (('005xx01Sv6o', 153245824, 
> '400'),('005xx01Sv6o', 153245823, '300'))");
>  printResultSet(rs); // THIS SHOULD BE A SINGLE ROW SCAN
> stmt.execute("DELETE FROM " + tenantView + " WHERE (ID1, EVENT_DATE, ID2) IN 
> (('005xx01Sv6o', 153245824, '400'),('005xx01Sv6o', 
> 153245823, '300'))");
>  viewConn.commit();
>  System.out.println("Delete End");
> rs = stmt.executeQuery("SELECT ID1, ID2, EVENT_DATE FROM " + tenantView );
>  printResultSet(rs);
> }
>  }
> private void printResultSet(ResultSet rs) throws SQLException {
>  StringBuilder builder = new StringBuilder();
>  while(rs.next()) {
>  for(int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
>  Object col = rs.getObject(i + 1);
>  if(col == null)
> { builder.append("null"); }
> else {
>  if(col instanceof Date)
> { DateFormat df = new SimpleDateFormat("-MM-dd HH:mm:ss"); 
> builder.append(df.format(col)); }
> else {
>  builder.append(col.toString());
>  }
>  }
>  builder.append(",");
>  }
>  builder.append("\n");
>  }
>  System.out.println(builder.toString());
>  }
> {code}
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Updated] (PHOENIX-5698) Phoenix Query with RVC IN list expression generates wrong scan with non-pk ordered pks

2020-02-29 Thread Xinyi Yan (Jira)


 [ 
https://issues.apache.org/jira/browse/PHOENIX-5698?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Xinyi Yan updated PHOENIX-5698:
---
Attachment: (was: PHOENIX-5698-4.x-HBase-1.3.patch)

> Phoenix Query with RVC IN list expression generates wrong scan with non-pk 
> ordered pks
> --
>
> Key: PHOENIX-5698
> URL: https://issues.apache.org/jira/browse/PHOENIX-5698
> Project: Phoenix
>  Issue Type: Bug
>Affects Versions: 4.15.0, 4.14.3
>Reporter: Daniel Wong
>Assignee: Xinyi Yan
>Priority: Major
>  Labels: DESC
> Attachments: PHOENIX-5698-4.14-HBase-1.3.patch, 
> PHOENIX-5698-4.x-HBase-1.3.patch, PHOENIX-5698.patch
>
>  Time Spent: 4h 40m
>  Remaining Estimate: 0h
>
> In the code below ideally we'd expect a SINGLE ROW DELETE plan client side. 
> However, this generates an incorrect scan with range ['tenant1
> 0CY005xx01Sv6o'). If the order of the RVCs is changed to row key order 
> Phoenix correctly generates a SINGLE ROW SCAN.  As we provide the full PK 
> this we expect a either tightly bounded range scan or a client side delete.  
> Instead we get a range scan on composite leading edge 
> TENANT_ID,KEY_PREFIX,ID1.
>  
> {code:java}
> @Test
>  public void testInListExpressionWithDescAgain() throws Exception {
>  String fullTableName = generateUniqueName();
>  String fullViewName = generateUniqueName();
>  String tenantView = generateUniqueName();
>  // create base table and global view using global connection
>  try (Connection conn = DriverManager.getConnection(getUrl()))
> { conn.setAutoCommit(true); Statement stmt = conn.createStatement(); 
> stmt.execute("CREATE TABLE " + fullTableName + "(\n" + " TENANT_ID CHAR(15) 
> NOT NULL,\n" + " KEY_PREFIX CHAR(3) NOT NULL,\n" + " CONSTRAINT PK PRIMARY 
> KEY (\n" + " TENANT_ID," + " KEY_PREFIX" + ")) MULTI_TENANT=TRUE"); 
> stmt.execute("CREATE VIEW " + fullViewName + "(\n" + " ID1 VARCHAR NOT 
> NULL,\n" + " ID2 VARCHAR NOT NULL,\n" + " EVENT_DATE DATE NOT NULL,\n" + " 
> CONSTRAINT PKVIEW PRIMARY KEY\n" + " (\n" + " ID1, ID2 DESC, EVENT_DATE 
> DESC\n" + ")) AS SELECT * FROM " + fullTableName + " WHERE KEY_PREFIX = 
> '0CY'"); }
> // create and use a tenant specific view to write data
>  try (Connection viewConn = DriverManager.getConnection(TENANT_SPECIFIC_URL1) 
> ) {
>  viewConn.setAutoCommit(true); //need autocommit for serverside deletion
>  Statement stmt = viewConn.createStatement();
>  stmt.execute("CREATE VIEW IF NOT EXISTS " + tenantView + " AS SELECT * FROM 
> " + fullViewName );
>  viewConn.createStatement().execute("UPSERT INTO " + tenantView + "(ID1, ID2, 
> EVENT_DATE) VALUES ('005xx01Sv6o', '300', 153245823)");
>  viewConn.createStatement().execute("UPSERT INTO " + tenantView + "(ID1, ID2, 
> EVENT_DATE) VALUES ('005xx01Sv6o', '400', 153245824)");
>  viewConn.createStatement().execute("UPSERT INTO " + tenantView + "(ID1, ID2, 
> EVENT_DATE) VALUES ('005xx01Sv6o', '500', 153245825)");
>  viewConn.commit();
> ResultSet rs = stmt.executeQuery("SELECT ID1, ID2, EVENT_DATE FROM " + 
> tenantView );
>  printResultSet(rs);
> System.out.println("Delete Start");
> rs = stmt.executeQuery("EXPLAIN DELETE FROM " + tenantView + " WHERE (ID1, 
> EVENT_DATE, ID2) IN (('005xx01Sv6o', 153245824, 
> '400'),('005xx01Sv6o', 153245823, '300'))");
>  printResultSet(rs); // THIS SHOULD BE A SINGLE ROW SCAN
> stmt.execute("DELETE FROM " + tenantView + " WHERE (ID1, EVENT_DATE, ID2) IN 
> (('005xx01Sv6o', 153245824, '400'),('005xx01Sv6o', 
> 153245823, '300'))");
>  viewConn.commit();
>  System.out.println("Delete End");
> rs = stmt.executeQuery("SELECT ID1, ID2, EVENT_DATE FROM " + tenantView );
>  printResultSet(rs);
> }
>  }
> private void printResultSet(ResultSet rs) throws SQLException {
>  StringBuilder builder = new StringBuilder();
>  while(rs.next()) {
>  for(int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
>  Object col = rs.getObject(i + 1);
>  if(col == null)
> { builder.append("null"); }
> else {
>  if(col instanceof Date)
> { DateFormat df = new SimpleDateFormat("-MM-dd HH:mm:ss"); 
> builder.append(df.format(col)); }
> else {
>  builder.append(col.toString());
>  }
>  }
>  builder.append(",");
>  }
>  builder.append("\n");
>  }
>  System.out.println(builder.toString());
>  }
> {code}
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Updated] (PHOENIX-5496) Ensure that we handle all server-side mutation codes on the client

2020-02-29 Thread Neha Gupta (Jira)


 [ 
https://issues.apache.org/jira/browse/PHOENIX-5496?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Neha Gupta updated PHOENIX-5496:

Attachment: PHOENIX-5496.master.v1.patch

> Ensure that we handle all server-side mutation codes on the client
> --
>
> Key: PHOENIX-5496
> URL: https://issues.apache.org/jira/browse/PHOENIX-5496
> Project: Phoenix
>  Issue Type: Bug
>Affects Versions: 4.15.0, 5.1.0
>Reporter: Chinmay Kulkarni
>Assignee: Neha Gupta
>Priority: Major
> Fix For: 4.15.1, 5.1.1
>
> Attachments: PHOENIX-5496.4.x-HBase-1.3.patch, 
> PHOENIX-5496.4.x-HBase-1.3.v1.patch, PHOENIX-5496.master.patch, 
> PHOENIX-5496.master.v1.patch, PHOENIX-5496.patch, PHOENIX-5496.v1.patch, 
> PHOENIX-5496.v2.patch, PHOENIX-5496.v3.patch
>
>  Time Spent: 4h
>  Remaining Estimate: 0h
>
> There are many instances throughout wherein we set a certain error mutation 
> code in the RPC callback, however we do not handle these mutation codes on 
> the client.
> For example: 
> If the metadata rows for a tableKey are no longer in that SYSCAT region, 
> checkTableKeyInRegion() fails, the metadata for this table is not written to 
> SYSCAT and [the TABLE_NOT_IN_REGION mutation code is 
> set|https://github.com/apache/phoenix/blob/11997d48d1957cf613526f01c5ccbe2812cf095d/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java#L1785-L1790].
> This is handled for 1 retry inside 
> [CQSI.metaDataCoprocessorExec|https://github.com/apache/phoenix/blob/11997d48d1957cf613526f01c5ccbe2812cf095d/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java#L1568-L1570],
>  but if this happens again, it is returned back to the client where it goes 
> to the default case and succeeds.
> Apart from the fact that partial metadata updates are possible leading to 
> orphan metadata rows in system tables, this also wrongly returns success for 
> clients even though there is no record of that table/view being created 
> inside Phoenix's system tables.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Assigned] (PHOENIX-5753) Fix erroneous query result when RVC is clipped with desc column

2020-02-29 Thread chenglei (Jira)


 [ 
https://issues.apache.org/jira/browse/PHOENIX-5753?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

chenglei reassigned PHOENIX-5753:
-

Assignee: chenglei

> Fix erroneous query result when RVC is clipped with desc column
> ---
>
> Key: PHOENIX-5753
> URL: https://issues.apache.org/jira/browse/PHOENIX-5753
> Project: Phoenix
>  Issue Type: Bug
>Affects Versions: 5.0.0, 4.15.0
>Reporter: chenglei
>Assignee: chenglei
>Priority: Major
>  Labels: DESC
> Fix For: 4.16.0
>
>
> Given following table and data:
> {code:java}
>CREATE TABLE  test
>(
> pk1 INTEGER NOT NULL ,  
> pk2 INTEGER NOT NULL, 
> pk3 INTEGER NOT NULL, 
> pk4 INTEGER NOT NULL, 
> v INTEGER, CONSTRAINT PK PRIMARY KEY(pk1,pk2,pk3 desc,pk4))
>)
> {code}
>   Noticed pk3 is DESC.
> {code:java}
>UPSERT INTO test (pk1, pk2, pk3, pk4, v) VALUES (1,3,4,10,1)
> {code}
> If we execute the following sql:
> {code:java}
>  select * from test
>  where (pk1 >=1 and pk1<=2) and (pk2>=3 and pk2<=4) and (pk3,pk4) < (5,7)
> {code}
> the returned result is empty, but obviously, the above inserted row 
> (1,3,4,10,1) should be returned.
> I think this problem is introduced by PHOENIX-3383 and PHOENIX-4841, when we 
> clip the {{(pk3,pk4) < (5,7)}} because {{pk3}} is {{DESC}}  by following line 
> 260 in {{WhereOptimizer.pushKeyExpressionsToScan}} , {{(pk3,pk4) < (5,7)}} is 
> clipped to {{pk3 <= 5}} and {{pk4 < 7}} .
> {code:java}
> 257List leftRanges = clipLeft(schema, 
> slot.getPKPosition()
> 258+ slotOffset - clipLeftSpan, clipLeftSpan, 
> keyRanges, ptr);
> 259keyRanges =
> 260clipRight(schema, slot.getPKPosition() + 
> slotOffset - 1, keyRanges,
> 261leftRanges, ptr);
> 262if (prevSortOrder == SortOrder.DESC) {
> 263leftRanges = invertKeyRanges(leftRanges);
> 264}
> 265slotSpanArray[cnf.size()] = clipLeftSpan-1;
> 266cnf.add(leftRanges);
> 267clipLeftSpan = 0;
> 268prevSortOrder = sortOrder;
> 269// since we have to clip the portion with the same 
> sort order, we can no longer
> 270// extract the nodes from the where clause
> 271// for eg. for the schema A VARCHAR DESC, B VARCHAR 
> ASC and query
> 272//   WHERE (A,B) < ('a','b')
> 273// the range (* - a\xFFb) is converted to (~a-*)(*-b)
> 274// so we still need to filter on A,B
> 275stopExtracting = true;
> 276}
> {code}
> Eventually after we completed the  
> {{WhereOptimizer.pushKeyExpressionsToScan}}, the result
> {{ScanRanges.ranges}} is  [[[1 - 2]], [[3 - 4]], [[~5 - *)], [(* - 7)]],  
> {{ScanRanges.useSkipScanFilter}} is {{true}}  and {{SkipScanFilter}} is also 
> [[[1 - 2]], [[3 - 4]], [[~5 - *)], [(* - 7)]], so the  the above inserted row 
> (1,3,4,10,1) could not be retrieved.
> But as we know, {{(pk3,pk4) < (5,7)}} is not semantically equals to {{pk3 <= 
> 5}} and {{pk4 < 7}} , we could only have
>   {{pk3 <= 5}}  but not  {{pk4 < 7}}, so when we clipped  {{(pk3,pk4) < 
> (5,7)}}  to {{pk3 <= 5}} , we could  simply skip remaining columns of this 
> RVC.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Updated] (PHOENIX-5753) Fix erroneous query result when RVC is clipped with desc column

2020-02-29 Thread chenglei (Jira)


 [ 
https://issues.apache.org/jira/browse/PHOENIX-5753?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

chenglei updated PHOENIX-5753:
--
Description: 
Given following table and data:
{code:java}
   CREATE TABLE  test
   (
pk1 INTEGER NOT NULL ,  
pk2 INTEGER NOT NULL, 
pk3 INTEGER NOT NULL, 
pk4 INTEGER NOT NULL, 
v INTEGER, CONSTRAINT PK PRIMARY KEY(pk1,pk2,pk3 desc,pk4))
   )
{code}
  Noticed pk3 is DESC.
{code:java}
   UPSERT INTO test (pk1, pk2, pk3, pk4, v) VALUES (1,3,4,10,1)
{code}

If we execute the following sql:
{code:java}
 select * from test
 where (pk1 >=1 and pk1<=2) and (pk2>=3 and pk2<=4) and (pk3,pk4) < (5,7)
{code}

the returned result is empty, but obviously, the above inserted row 
(1,3,4,10,1) should be returned.

I think this problem is introduced by PHOENIX-3383 and PHOENIX-4841, when we 
clip the {{(pk3,pk4) < (5,7)}} because {{pk3}} is {{DESC}}  by following line 
260 in {{WhereOptimizer.pushKeyExpressionsToScan}} , {{(pk3,pk4) < (5,7)}} is 
clipped to {{pk3 <= 5}} and {{pk4 < 7}} .

{code:java}
257List leftRanges = clipLeft(schema, 
slot.getPKPosition()
258+ slotOffset - clipLeftSpan, clipLeftSpan, 
keyRanges, ptr);
259keyRanges =
260clipRight(schema, slot.getPKPosition() + 
slotOffset - 1, keyRanges,
261leftRanges, ptr);
262if (prevSortOrder == SortOrder.DESC) {
263leftRanges = invertKeyRanges(leftRanges);
264}
265slotSpanArray[cnf.size()] = clipLeftSpan-1;
266cnf.add(leftRanges);
267clipLeftSpan = 0;
268prevSortOrder = sortOrder;
269// since we have to clip the portion with the same sort 
order, we can no longer
270// extract the nodes from the where clause
271// for eg. for the schema A VARCHAR DESC, B VARCHAR ASC 
and query
272//   WHERE (A,B) < ('a','b')
273// the range (* - a\xFFb) is converted to (~a-*)(*-b)
274// so we still need to filter on A,B
275stopExtracting = true;
276}
{code}

Eventually after we completed the  {{WhereOptimizer.pushKeyExpressionsToScan}}, 
the result
{{ScanRanges.ranges}} is  [[[1 - 2]], [[3 - 4]], [[~5 - *)], [(* - 7)]],  
{{ScanRanges.useSkipScanFilter}} is {{true}}  and {{SkipScanFilter}} is also 
[[[1 - 2]], [[3 - 4]], [[~5 - *)], [(* - 7)]], so the  the above inserted row 
(1,3,4,10,1) could not be retrieved.

But as we know, {{(pk3,pk4) < (5,7)}} is not semantically equals to {{pk3 <= 
5}} and {{pk4 < 7}} , we could only have
  {{pk3 <= 5}}  but not  {{pk4 < 7}}, so when we clipped  {{(pk3,pk4) < (5,7)}} 
 to {{pk3 <= 5}} , we could  simply skip remaining columns of this RVC.


  was:
Given following table and data:
{code:java}
   CREATE TABLE  test
   (
pk1 INTEGER NOT NULL ,  
pk2 INTEGER NOT NULL, 
pk3 INTEGER NOT NULL, 
pk4 INTEGER NOT NULL, 
v INTEGER, CONSTRAINT PK PRIMARY KEY(pk1,pk2,pk3 desc,pk4))
   )
{code}
  Noticed pk3 is DESC.
{code:java}
   UPSERT INTO test (pk1, pk2, pk3, pk4, v) VALUES (1,3,4,10,1)
{code}

If we execute the following sql:
{code:java}
 select * from test
 where (pk1 >=1 and pk1<=2) and (pk2>=3 and pk2<=4) and (pk3,pk4) < (5,7)
{code}

the returned result is empty, but obviously, the above inserted row 
(1,3,4,10,1) should be returned.

I think this problem is introduced by PHOENIX-3383 and PHOENIX-4841, when we 
clip the {{(pk3,pk4) < (5,7)}} because {{pk3}} is {{DESC}}  by following line 
260 in {{WhereOptimizer.pushKeyExpressionsToScan}} , {{(pk3,pk4) < (5,7)}} is 
clipped to {{pk3 <= 5}} and {{pk4 < 7}} .

{code:java}
257List leftRanges = clipLeft(schema, 
slot.getPKPosition()
258+ slotOffset - clipLeftSpan, clipLeftSpan, 
keyRanges, ptr);
259keyRanges =
260clipRight(schema, slot.getPKPosition() + 
slotOffset - 1, keyRanges,
261leftRanges, ptr);
262if (prevSortOrder == SortOrder.DESC) {
263leftRanges = invertKeyRanges(leftRanges);
264}
265slotSpanArray[cnf.size()] = clipLeftSpan-1;
266cnf.add(leftRanges);
267clipLeftSpan = 0;
268prevSortOrder = sortOrder;
269// since we have to clip the portion with the same sort 
order, we can no longer
270// extract the nodes from the where clause
271// for eg. for the schema A