private KeySlots newKeyParts(KeySlot slot, Expression extractNode, KeyRange keyRange) { if (keyRange == null) { return EMPTY_KEY_SLOTS; } List<KeyRange> keyRanges = Collections.<KeyRange>singletonList(keyRange); return newKeyParts(slot, extractNode, keyRanges); }
@Override public KeySlots visitLeave(InListExpression node, List<KeySlots> childParts) { if (childParts.isEmpty()) { return null; } List<Expression> keyExpressions = node.getKeyExpressions(); Set<KeyRange> ranges = Sets.newHashSetWithExpectedSize(keyExpressions.size()); KeySlot childSlot = childParts.get(0).getSlots().get(0); KeyPart childPart = childSlot.getKeyPart(); // Handles cases like WHERE substr(foo,1,3) IN ('aaa','bbb') for (Expression key : keyExpressions) { KeyRange range = childPart.getKeyRange(CompareOp.EQUAL, key); if (range == null) { return null; } if (range != KeyRange.EMPTY_RANGE) { // null means it can't possibly be in range ranges.add(range); } } return newKeyParts(childSlot, node, new ArrayList<KeyRange>(ranges)); }
@Override public KeySlots visitLeave(ComparisonExpression node, List<KeySlots> childParts) { // Delay adding to extractedNodes, until we're done traversing, // since we can't yet tell whether or not the PK column references // are contiguous if (childParts.isEmpty()) { return null; } Expression rhs = node.getChildren().get(1); KeySlots childSlots = childParts.get(0); KeySlot childSlot = childSlots.getSlots().get(0); KeyPart childPart = childSlot.getKeyPart(); //SortOrder sortOrder = childPart.getColumn().getSortOrder(); CompareOp op = node.getFilterOp(); //CompareOp op = sortOrder.transform(node.getFilterOp()); KeyRange keyRange = childPart.getKeyRange(op, rhs); return newKeyParts(childSlot, node, keyRange); }
theSlot = theSlot.concatExtractNodes(slotExtractNodes); return newKeyParts( theSlot, partialExtraction ? slotExtractNodes : Collections.<Expression>singletonList(orExpression),
theSlot = new KeySlot(new BaseKeyPart(table, table.getPKColumns().get(initialPos), slotExtractNodes), initialPos, 1, EVERYTHING_RANGES, null); return newKeyParts( theSlot, partialExtraction ? slotExtractNodes : Collections.<Expression>singletonList(orExpression),
return newKeyParts(childSlot, node.endsWithOnlyWildcard() ? node : null, range);
return newKeyParts(childSlot, node.endsWithOnlyWildcard() ? node : null, keyRange);
@Override public KeySlots visitLeave(InListExpression node, List<KeySlots> childParts) { if (childParts.isEmpty()) { return null; } List<Expression> keyExpressions = node.getKeyExpressions(); Set<KeyRange> ranges = Sets.newHashSetWithExpectedSize(keyExpressions.size()); KeySlot childSlot = childParts.get(0).getSlots().get(0); KeyPart childPart = childSlot.getKeyPart(); // Handles cases like WHERE substr(foo,1,3) IN ('aaa','bbb') for (Expression key : keyExpressions) { KeyRange range = childPart.getKeyRange(CompareOp.EQUAL, key); if (range == null) { return null; } if (range != KeyRange.EMPTY_RANGE) { // null means it can't possibly be in range ranges.add(range); } } return newKeyParts(childSlot, node, new ArrayList<KeyRange>(ranges)); }
@Override public KeySlots visitLeave(IsNullExpression node, List<KeySlots> childParts) { if (childParts.isEmpty()) { return null; } KeySlots childSlots = childParts.get(0); KeySlot childSlot = childSlots.getSlots().get(0); PColumn column = childSlot.getKeyPart().getColumn(); PDataType type = column.getDataType(); boolean isFixedWidth = type.isFixedWidth(); // Nothing changes for IS NULL and IS NOT NULL when DESC since // we represent NULL the same way for ASC and DESC if (isFixedWidth) { // if column can't be null return node.isNegate() ? null : newKeyParts(childSlot, node, type.getKeyRange(new byte[SchemaUtil.getFixedByteSize(column)], true, KeyRange.UNBOUND, true)); } else { KeyRange keyRange = node.isNegate() ? KeyRange.IS_NOT_NULL_RANGE : KeyRange.IS_NULL_RANGE; return newKeyParts(childSlot, node, keyRange); } }
@Override public KeySlots visitLeave(IsNullExpression node, List<KeySlots> childParts) { if (childParts.isEmpty()) { return null; } KeySlots childSlots = childParts.get(0); KeySlot childSlot = childSlots.iterator().next(); PColumn column = childSlot.getKeyPart().getColumn(); PDataType type = column.getDataType(); boolean isFixedWidth = type.isFixedWidth(); if (isFixedWidth) { // if column can't be null return node.isNegate() ? null : newKeyParts(childSlot, node, type.getKeyRange(new byte[SchemaUtil.getFixedByteSize(column)], true, KeyRange.UNBOUND, true)); } else { KeyRange keyRange = node.isNegate() ? KeyRange.IS_NOT_NULL_RANGE : KeyRange.IS_NULL_RANGE; return newKeyParts(childSlot, node, keyRange); } }
@Override public KeySlots visitLeave(InListExpression node, List<KeySlots> childParts) { if (childParts.isEmpty()) { return null; } List<Expression> keyExpressions = node.getKeyExpressions(); Set<KeyRange> ranges = Sets.newHashSetWithExpectedSize(keyExpressions.size()); KeySlot childSlot = childParts.get(0).iterator().next(); KeyPart childPart = childSlot.getKeyPart(); // Handles cases like WHERE substr(foo,1,3) IN ('aaa','bbb') for (Expression key : keyExpressions) { KeyRange range = childPart.getKeyRange(CompareOp.EQUAL, key); if (range == null) { return null; } if (range != KeyRange.EMPTY_RANGE) { // null means it can't possibly be in range ranges.add(range); } } return newKeyParts(childSlot, node, new ArrayList<KeyRange>(ranges), null); }
@Override public KeySlots visitLeave(ComparisonExpression node, List<KeySlots> childParts) { // Delay adding to extractedNodes, until we're done traversing, // since we can't yet tell whether or not the PK column references // are contiguous if (childParts.isEmpty()) { return null; } Expression rhs = node.getChildren().get(1); KeySlots childSlots = childParts.get(0); KeySlot childSlot = childSlots.getSlots().get(0); KeyPart childPart = childSlot.getKeyPart(); //SortOrder sortOrder = childPart.getColumn().getSortOrder(); CompareOp op = node.getFilterOp(); //CompareOp op = sortOrder.transform(node.getFilterOp()); KeyRange keyRange = childPart.getKeyRange(op, rhs); return newKeyParts(childSlot, node, keyRange); }
private KeySlots newKeyParts(KeySlot slot, Expression extractNode, KeyRange keyRange) { if (keyRange == null) { return EMPTY_KEY_SLOTS; } List<KeyRange> keyRanges = slot.getPKSpan() == 1 ? Collections.<KeyRange>singletonList(keyRange) : EVERYTHING_RANGES; KeyRange minMaxRange = null; if (slot.getPKSpan() > 1) { int initPosition = (table.getBucketNum() ==null ? 0 : 1) + (this.context.getConnection().getTenantId() != null && table.isMultiTenant() ? 1 : 0) + (table.getViewIndexId() == null ? 0 : 1); if (initPosition == slot.getPKPosition()) { minMaxRange = keyRange; } else { // If we cannot set the minMaxRange, then we must not extract the expression since // we wouldn't be constraining the range at all based on it. extractNode = null; } } return newKeyParts(slot, extractNode, keyRanges, minMaxRange); }
@Override public KeySlots visitLeave(ComparisonExpression node, List<KeySlots> childParts) { // Delay adding to extractedNodes, until we're done traversing, // since we can't yet tell whether or not the PK column references // are contiguous if (childParts.isEmpty()) { return null; } Expression rhs = node.getChildren().get(1); KeySlots childSlots = childParts.get(0); KeySlot childSlot = childSlots.iterator().next(); KeyPart childPart = childSlot.getKeyPart(); SortOrder sortOrder = childPart.getColumn().getSortOrder(); CompareOp op = sortOrder.transform(node.getFilterOp()); KeyRange keyRange = childPart.getKeyRange(op, rhs); return newKeyParts(childSlot, node, keyRange); }
private KeySlots newKeyParts(KeySlot slot, Expression extractNode, KeyRange keyRange) { if (keyRange == null) { return EMPTY_KEY_SLOTS; } List<KeyRange> keyRanges = Collections.<KeyRange>singletonList(keyRange); return newKeyParts(slot, extractNode, keyRanges); }
theSlot = new KeySlot(new BaseKeyPart(table, table.getPKColumns().get(initialPos), slotExtractNodes), initialPos, 1, EVERYTHING_RANGES, null); return newKeyParts( theSlot, partialExtraction ? slotExtractNodes : Collections.<Expression>singletonList(orExpression),
return newKeyParts(childSlot, node.endsWithOnlyWildcard() ? node : null, range);
@Override public KeySlots visitLeave(IsNullExpression node, List<KeySlots> childParts) { if (childParts.isEmpty()) { return null; } KeySlots childSlots = childParts.get(0); KeySlot childSlot = childSlots.getSlots().get(0); PColumn column = childSlot.getKeyPart().getColumn(); PDataType type = column.getDataType(); boolean isFixedWidth = type.isFixedWidth(); // Nothing changes for IS NULL and IS NOT NULL when DESC since // we represent NULL the same way for ASC and DESC if (isFixedWidth) { // if column can't be null return node.isNegate() ? null : newKeyParts(childSlot, node, type.getKeyRange(new byte[SchemaUtil.getFixedByteSize(column)], true, KeyRange.UNBOUND, true)); } else { KeyRange keyRange = node.isNegate() ? KeyRange.IS_NOT_NULL_RANGE : KeyRange.IS_NULL_RANGE; return newKeyParts(childSlot, node, keyRange); } }