Skip to content

Commit

Permalink
PHOENIX-5171 SkipScan incorrectly filters composite primary key which…
Browse files Browse the repository at this point in the history
… the key range contains all values.
  • Loading branch information
lhofhansl committed Sep 9, 2020
1 parent f4fd335 commit f5cc0ad
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -713,4 +713,37 @@ public void testRVCClipBug5753() throws Exception {
assertResultSet(rs, new Object[][]{{1,3,2,10},{1,3,5,6}});
}
}

@Test
public void testKeyRangesContainsAllValues() throws Exception {
String tableName = generateUniqueName();
String ddl = "CREATE TABLE IF NOT EXISTS " + tableName + "(" +
" vdate VARCHAR, " +
" tab VARCHAR, " +
" dev TINYINT NOT NULL, " +
" app VARCHAR, " +
" target VARCHAR, " +
" channel VARCHAR, " +
" one VARCHAR, " +
" two VARCHAR, " +
" count1 INTEGER, " +
" count2 INTEGER, " +
" CONSTRAINT PK PRIMARY KEY (vdate,tab,dev,app,target,channel,one,two))";

try (Connection conn = DriverManager.getConnection(getUrl())) {
conn.createStatement().execute(ddl);
conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('2018-02-14','channel_agg',2,null,null,'A004',null,null,2,2)");
conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('2018-02-14','channel_agg',2,null,null,null,null,null,2,2)");
conn.commit();

ResultSet rs = conn.createStatement().executeQuery(
"SELECT * FROM " + tableName +
" WHERE dev = 2 AND vdate BETWEEN '2018-02-10' AND '2019-02-19'" +
" AND tab = 'channel_agg' AND channel='A004'");

assertTrue(rs.next());
assertEquals("2018-02-14", rs.getString(1));
assertFalse(rs.next());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,9 @@ public static int setKey(RowKeySchema schema, List<List<KeyRange>> slots, int[]
* for the same reason. However, if the type is variable width
* continue building the key because null values will be filtered
* since our separator byte will be appended and incremented.
* 3) if the range includes everything as we cannot add any more useful
* information to the key after that.
*/
lastUnboundUpper = false;
if ( range.isUnbound(bound) &&
( bound == Bound.UPPER || isFixedWidth || range == KeyRange.EVERYTHING_RANGE) ){
if (range.isUnbound(bound) && (bound == Bound.UPPER || isFixedWidth)) {
lastUnboundUpper = (bound == Bound.UPPER);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,46 @@ public static synchronized Collection<Object> data() {
QueryConstants.SEPARATOR_BYTE_ARRAY,
Bytes.toBytes("1") ),
ByteUtil.concat(Bytes.toBytes("f"),QueryConstants.SEPARATOR_BYTE_ARRAY,
Bytes.toBytes("b") )),
Bytes.toBytes("b"),QueryConstants.SEPARATOR_BYTE_ARRAY,
QueryConstants.SEPARATOR_BYTE_ARRAY, Bytes.toBytes("1") )),
new Include(ByteUtil.concat(Bytes.toBytes("f"),QueryConstants.SEPARATOR_BYTE_ARRAY,
Bytes.toBytes("b"), QueryConstants.SEPARATOR_BYTE_ARRAY,
QueryConstants.SEPARATOR_BYTE_ARRAY,
Bytes.toBytes("1") ) ) )
);
testCases.addAll(
foreach(new KeyRange[][]{{
PVarchar.INSTANCE.getKeyRange(Bytes.toBytes("2018-02-10"), true, Bytes.toBytes("2019-02-19"), true),
},
{
PVarchar.INSTANCE.getKeyRange(Bytes.toBytes("channel"), true, Bytes.toBytes("channel"), true),
},
{
PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("2"), true),
},
{
KeyRange.EVERYTHING_RANGE,
},
{
KeyRange.EVERYTHING_RANGE,
},
{
PVarchar.INSTANCE.getKeyRange(Bytes.toBytes("A004"), true, Bytes.toBytes("A004"), true),
},
},
new int[] {0, 0, 1, 0, 0, 0, 0, 0},
null,
new SeekNext(
ByteUtil.concat(Bytes.toBytes("2018-02-14"), QueryConstants.SEPARATOR_BYTE_ARRAY, Bytes.toBytes("channel"),
QueryConstants.SEPARATOR_BYTE_ARRAY, Bytes.toBytes("2")),
ByteUtil.concat(Bytes.toBytes("2018-02-14"), QueryConstants.SEPARATOR_BYTE_ARRAY, Bytes.toBytes("channel"),
QueryConstants.SEPARATOR_BYTE_ARRAY, Bytes.toBytes("2"), QueryConstants.SEPARATOR_BYTE_ARRAY, QueryConstants.SEPARATOR_BYTE_ARRAY,
Bytes.toBytes("A004"))),
new Include(ByteUtil.concat(Bytes.toBytes("2018-02-15"), QueryConstants.SEPARATOR_BYTE_ARRAY, Bytes.toBytes("channel"),
QueryConstants.SEPARATOR_BYTE_ARRAY, Bytes.toBytes("2"), QueryConstants.SEPARATOR_BYTE_ARRAY, QueryConstants.SEPARATOR_BYTE_ARRAY,
Bytes.toBytes("A004")))
)
);
testCases.addAll(
foreach(new KeyRange[][]{{
PVarchar.INSTANCE.getKeyRange(Bytes.toBytes("20160116121006"), true, Bytes.toBytes("20160116181006"), true),
Expand Down

0 comments on commit f5cc0ad

Please sign in to comment.