zstan commented on code in PR #13225:
URL: https://github.com/apache/ignite/pull/13225#discussion_r3490147129
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/SelectByKeyFieldTest.java:
##########
@@ -304,32 +193,158 @@ private void checkCompositePk(
}
/** */
- private void checkCompositePkWithDifferentCmpOperations(boolean
useBinaryObject) {
+ @Test
+ public void testCompositePkSearchByPartOfKeyTableScan() {
+ compositePkEqualitySearchByPartOfKey(true);
+ }
+
+ /** */
+ @Test
+ public void testCompositePkSearchByPartOfKeyIdxScan() {
+ compositePkEqualitySearchByPartOfKey(false);
+ }
+
+ /**
+ * Tests composite primary key equality search using only part of the key
(single column).
+ * Verifies that queries with equality comparison on either the {@code id}
or {@code name} column
+ * return correct results using either table scan or index scan depending
on the {@code tableScan} flag.
+ *
+ * @param tableScan {@code true} to test with table scan, {@code false} to
test with index scan.
+ */
+ public void compositePkEqualitySearchByPartOfKey(boolean tableScan) {
sql("create table PUBLIC.PERSON(id int, name varchar, surname varchar,
age int, primary key(id, name))");
- for (int i = 0; i < 10; i++) {
- sql(
- "insert into PUBLIC.PERSON(id, name, surname, age) values (?,
?, ?, ?)",
- i, "foo" + i, "bar" + i, 18 + i
- );
- }
+ fillTable();
+
+ List<List<?>> sqlRs = sql("select _key, id, name from PUBLIC.PERSON
order by id");
+ BinaryObject _key = (BinaryObject)sqlRs.get(6).get(0);
+ int id = (Integer)sqlRs.get(6).get(1);
+ String name = (String)sqlRs.get(6).get(2);
+
+ // Select by uniq id.
+ assertQuery("select /*+ DISABLE_RULE('" + (tableScan ?
"LogicalIndexScanConverterRule" : "LogicalTableScanConverterRule") +
+ "') */ id, name, age, _key from PUBLIC.PERSON where id = ?")
+ .withParams(id)
+ .matches(tableScan ?
+ QueryChecker.containsTableScan("PUBLIC", "PERSON") :
+ QueryChecker.containsIndexScan("PUBLIC", "PERSON",
PRIMARY_KEY_INDEX)
+ )
+ .columnNames("ID", "NAME", "AGE", KEY_FIELD_NAME)
+ .returns(id, name, 24, _key)
+ .check();
+
+ // Select by uniq name.
+ assertQuery("select /*+ DISABLE_RULE('" + (tableScan ?
"LogicalIndexScanConverterRule" : "LogicalTableScanConverterRule") +
+ "') */ id, name, age, _key from PUBLIC.PERSON where name = ?")
+ .withParams(name)
+ .matches(tableScan ?
+ QueryChecker.containsTableScan("PUBLIC", "PERSON") :
+ QueryChecker.containsIndexScan("PUBLIC", "PERSON",
PRIMARY_KEY_INDEX)
+ )
+ .columnNames("ID", "NAME", "AGE", KEY_FIELD_NAME)
+ .returns(id, name, 24, _key)
+ .check();
+ }
+
+ /** */
+ @Test
+ public void testCompositePkWithOrderByKeyTableScan() {
+ compositePkWithOrderByKey(true);
+ }
+
+ /** */
+ @Test
+ public void testCompositePkWithOrderByKeyIdxScan() {
+ compositePkWithOrderByKey(false);
+ }
+
+ /**
+ * Tests composite primary key ordering by {@code _key}.
+ * Verifies that ordering by the composite primary key produces correct
results
+ * when comparing binary objects using {@link #binaryObjectCmpForDml}.
+ */
+ public void compositePkWithOrderByKey(boolean tableScan) {
+ sql("create table PUBLIC.PERSON(id int, name varchar, surname varchar,
age int, primary key(id, name))");
+
+ fillTable();
+
+ List<List<?>> sqlRs = sql("select id, name, age, _key from
PUBLIC.PERSON");
+ sqlRs.sort((o1, o2) -> binaryObjectCmpForDml(o1.get(3), o2.get(3)));
+
+ QueryChecker qryChecker = assertQuery("select /*+ DISABLE_RULE('" +
Review Comment:
because i want to run this and all other tests for index and table scan
operations
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]