use of org.apache.ignite.internal.sql.engine.schema.IgniteIndex in project ignite-3 by apache.
the class TableDmlPlannerTest method updateCachesDependentIndexScan.
/**
* UpdateCachesDependentIndexScan.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*
* @throws Exception If failed.
*/
@Test
public void updateCachesDependentIndexScan() throws Exception {
TestTable tbl = createTable("TEST", IgniteDistributions.random(), "VAL", Integer.class);
tbl.addIndex(new IgniteIndex(RelCollations.of(0), "IDX", tbl));
IgniteSchema schema = createSchema(tbl);
String sql = "update test set val = 2 * val where val between 2 and 10";
RelNode phys = physicalPlan(sql, schema, "LogicalTableScanConverterRule");
assertNotNull(phys);
String invalidPlanMsg = "Invalid plan:\n" + RelOptUtil.toString(phys);
IgniteTableModify modifyNode = findFirstNode(phys, byClass(IgniteTableModify.class));
assertThat(invalidPlanMsg, modifyNode, notNullValue());
assertThat(invalidPlanMsg, modifyNode.getInput(), instanceOf(Spool.class));
Spool spool = (Spool) modifyNode.getInput();
assertThat(invalidPlanMsg, spool.readType, equalTo(Spool.Type.EAGER));
assertThat(invalidPlanMsg, findFirstNode(phys, byClass(IgniteIndexScan.class)), notNullValue());
}
use of org.apache.ignite.internal.sql.engine.schema.IgniteIndex in project ignite-3 by apache.
the class LogicalOrToUnionRule method idxCollationCheck.
/**
* Compares intersection (currently beginning position) of condition and index fields.
* This rule need to be triggered only if appropriate indexes will be found otherwise it`s not applicable.
*
* @param call Set of appropriate RelNode.
* @param operands Operands from OR expression.
*/
private boolean idxCollationCheck(RelOptRuleCall call, List<RexNode> operands) {
final IgniteLogicalTableScan scan = call.rel(0);
InternalIgniteTable tbl = scan.getTable().unwrap(InternalIgniteTable.class);
IgniteTypeFactory typeFactory = Commons.typeFactory(scan.getCluster());
int fieldCnt = tbl.getRowType(typeFactory).getFieldCount();
BitSet idxsFirstFields = new BitSet(fieldCnt);
for (IgniteIndex idx : tbl.indexes().values()) {
List<RelFieldCollation> fieldCollations = idx.collation().getFieldCollations();
if (!CollectionUtils.nullOrEmpty(fieldCollations)) {
idxsFirstFields.set(fieldCollations.get(0).getFieldIndex());
}
}
Mappings.TargetMapping mapping = scan.requiredColumns() == null ? null : Commons.inverseMapping(scan.requiredColumns(), fieldCnt);
for (RexNode op : operands) {
BitSet conditionFields = new BitSet(fieldCnt);
new RexShuttle() {
@Override
public RexNode visitLocalRef(RexLocalRef inputRef) {
conditionFields.set(mapping == null ? inputRef.getIndex() : mapping.getSourceOpt(inputRef.getIndex()));
return inputRef;
}
}.apply(op);
if (!conditionFields.intersects(idxsFirstFields)) {
return false;
}
}
return true;
}
Aggregations