boolean useSkipScan = false; boolean hasRange = false; List<List<KeyRange>> rangesList = dataScanRanges.getRanges(); int rangesListSize = rangesList.size(); while (offset < nColumnsInCommon && offset < rangesListSize) { int rangeSpan = 1 + dataScanRanges.getSlotSpans()[offset]; if (offset + rangeSpan > nColumnsInCommon) { rangeSpan = nColumnsInCommon - offset; range = clipRange(dataScanRanges.getSchema(), offset, rangeSpan, range); offset = offset + rangeSpan; useSkipScan &= dataScanRanges.useSkipScanFilter(); slotSpan = slotSpan.length == cnf.size() ? slotSpan : Arrays.copyOf(slotSpan, cnf.size()); ScanRanges commonScanRanges = ScanRanges.create(dataScanRanges.getSchema(), cnf, slotSpan, null, useSkipScan, -1); return commonScanRanges;
private List<PSchema> buildSchemas(List<byte[]> keys, Region region, long clientTimeStamp, ImmutableBytesPtr cacheKey) throws IOException, SQLException { List<KeyRange> keyRanges = Lists.newArrayListWithExpectedSize(keys.size()); for (byte[] key : keys) { byte[] stopKey = ByteUtil.concat(key, QueryConstants.SEPARATOR_BYTE_ARRAY); ByteUtil.nextKey(stopKey, stopKey.length); keyRanges.add(PVarbinary.INSTANCE.getKeyRange(key, true, stopKey, false)); } Scan scan = new Scan(); scan.setTimeRange(MIN_TABLE_TIMESTAMP, clientTimeStamp); ScanRanges scanRanges = ScanRanges.createPointLookup(keyRanges); scanRanges.initializeScan(scan); scan.setFilter(scanRanges.getSkipScanFilter()); Cache<ImmutableBytesPtr, PMetaDataEntity> metaDataCache = GlobalCache.getInstance(this.env).getMetaDataCache(); List<PSchema> schemas = new ArrayList<PSchema>(); PSchema schema = null; try (RegionScanner scanner = region.getScanner(scan)) { for (int i = 0; i < keys.size(); i++) { schema = null; schema = getSchema(scanner, clientTimeStamp); if (schema == null) { return null; } metaDataCache.put(cacheKey, schema); schemas.add(schema); } return schemas; } }
Expression testExpression = InListExpression.create(Lists.newArrayList(lhs, firstRhs, secondRhs), false, context.getTempPtr(), context.getCurrentTable().getTable().rowKeyOrderOptimizable()); remaining = pushKeyExpressionsToScan(context, statement, testExpression); if (context.getScanRanges().isPointLookup()) { count++; break; // found the best match int pkSpan = context.getScanRanges().getBoundPkColumnCount() - offset; if (pkSpan <= maxPkSpan) { break; && (context.getScanRanges().isPointLookup() || context.getScanRanges().useSkipScanFilter()) && (remaining == null || remaining.equals(LiteralExpression.newConstant(true, Determinism.ALWAYS)));
private boolean explainSkipScan(StringBuilder buf) { ScanRanges scanRanges = context.getScanRanges(); if (scanRanges.isPointLookup()) { int keyCount = scanRanges.getPointLookupCount(); buf.append("POINT LOOKUP ON " + keyCount + " KEY" + (keyCount > 1 ? "S " : " ")); } else if (scanRanges.useSkipScanFilter()) { buf.append("SKIP SCAN "); int count = 1; boolean hasRanges = false; int nSlots = scanRanges.getBoundSlotCount(); for (int i = 0; i < nSlots; i++) { List<KeyRange> ranges = scanRanges.getRanges().get(i); count *= ranges.size(); for (KeyRange range : ranges) { hasRanges |= !range.isSingleKey(); } } buf.append("ON "); buf.append(count); buf.append(hasRanges ? " RANGE" : " KEY"); buf.append(count > 1 ? "S " : " "); } else { buf.append("RANGE SCAN "); } return scanRanges.useSkipScanFilter(); }
/** * Return true if the region with the start and end key * intersects with the scan ranges and false otherwise. * @param regionStartKey lower inclusive key * @param regionEndKey upper exclusive key * @param isLocalIndex true if the table being scanned is a local index * @return true if the scan range intersects with the specified lower/upper key * range */ public boolean intersectRegion(byte[] regionStartKey, byte[] regionEndKey, boolean isLocalIndex) { if (isEverything()) { return true; } if (isDegenerate()) { return false; } // Every range intersects all regions of a local index table if (isLocalIndex) { return true; } boolean crossesSaltBoundary = isSalted && ScanUtil.crossesPrefixBoundary(regionEndKey, ScanUtil.getPrefix(regionStartKey, SaltingUtil.NUM_SALTING_BYTES), SaltingUtil.NUM_SALTING_BYTES); return intersectScan(null, regionStartKey, regionEndKey, 0, crossesSaltBoundary) == HAS_INTERSECTION; }
KeyRange prefixRange = prefixScanRanges.getScanRange(); if (!prefixRange.lowerUnbound()) { startRegionBoundaryKey = prefixRange.getLowerRange(); if (columnsInCommon > 0 && prefixScanRanges.useSkipScanFilter()) { byte[] regionStartKey = regionInfo.getStartKey(); ImmutableBytesWritable ptr = context.getTempPtr(); clipKeyRangeBytes(prefixScanRanges.getSchema(), 0, columnsInCommon, regionStartKey, ptr, false); regionStartKey = ByteUtil.copyKeyBytesIfNecessary(ptr); if (!prefixScanRanges.intersectRegion(regionStartKey, regionInfo.getEndKey(), false)) { currentKeyBytes = endKey; regionIndex++; boolean everNotDelayed = false; while (intersectWithGuidePosts && (endKey.length == 0 || (gpsComparedToEndKey=currentGuidePost.compareTo(endKey)) <= 0)) { Scan newScan = scanRanges.intersectScan(scan, currentKeyBytes, currentGuidePostBytes, keyOffset, false); if (newScan != null) { Scan newScan = scanRanges.intersectScan(scan, currentKeyBytes, endKey, keyOffset, true); if(newScan != null) { ScanUtil.setLocalIndexAttributes(newScan, keyOffset, regionInfo.getStartKey(), if (scanRanges.isPointLookup() || pageLimit != null) { if (scanRanges.isPointLookup() && pageLimit != null) { this.estimatedRows = Long.valueOf(Math.min(scanRanges.getPointLookupCount(), pageLimit * parallelFactor)); } else if (scanRanges.isPointLookup()) {
ScanRanges scanRanges = ScanRanges.create(SchemaUtil.VAR_BINARY_SCHEMA, Collections.singletonList(keys), ScanUtil.SINGLE_COLUMN_SLOT_SPAN, null, true, -1); scanRanges.initializeScan(scan); Table txTable = indexMetaData.getTransactionContext().getTransactionalTable(htable, true); SkipScanFilter filter = scanRanges.getSkipScanFilter(); if (isRollback) { filter = new SkipScanFilter(filter,true);
QueryServicesOptions.DEFAULT_SMALL_SCAN_THRESHOLD); if (statement.getHint().hasHint(Hint.SMALL) || (scanRanges.isPointLookup() && scanRanges.getPointLookupCount() < smallScanThreshold)) { scan.setSmall(true); TimeRange rowTimestampRange = scanRanges.getRowTimestampRange();
@Override public MutationState execute() throws SQLException { // We have a point lookup, so we know we have a simple set of fully qualified // keys for our ranges ScanRanges ranges = context.getScanRanges(); Iterator<KeyRange> iterator = ranges.getPointLookupKeyIterator(); MultiRowMutationState mutation = new MultiRowMutationState(ranges.getPointLookupCount()); while (iterator.hasNext()) { mutation.put(new ImmutableBytesPtr(iterator.next().getLowerRange()), new RowMutationState(PRow.DELETE_MARKER, 0, statement.getConnection().getStatementExecutionCounter(), NULL_ROWTIMESTAMP_INFO, null)); } return new MutationState(dataPlan.getTableRef(), mutation, 0, maxSize, maxSizeBytes, connection); }
public static ScanRanges createPointLookup(List<KeyRange> keys) { return ScanRanges.create(SchemaUtil.VAR_BINARY_SCHEMA, Collections.singletonList(keys), ScanUtil.SINGLE_COLUMN_SLOT_SPAN, null, true, -1); }
PTable table1 = plan1.getTableRef().getTable(); PTable table2 = plan2.getTableRef().getTable(); int boundCount1 = plan1.getContext().getScanRanges().getBoundPkColumnCount(); int boundCount2 = plan2.getContext().getScanRanges().getBoundPkColumnCount(); return plan1.getContext().getScanRanges().getRanges().isEmpty() ? -1 : 1; return plan2.getContext().getScanRanges().getRanges().isEmpty() ? 1 : -1;
KeyRange minMaxRange = scanRanges.getMinMaxRange(); Iterator<byte[]> minMaxIterator = Collections.emptyIterator(); if (minMaxRange != KeyRange.EVERYTHING_RANGE) { if (!minMaxRange.isUnbound(bound)) { minMaxIterator = new RowKeyValueIterator(schema, scanRanges.getScanRange().getRange(bound)); int nRanges = forceSkipScan ? scanRanges.getRanges().size() : scanRanges.getBoundSlotCount(); for (int i = 0, minPos = 0; minPos < nRanges || minMaxIterator.hasNext(); i++) { List<KeyRange> ranges = minPos >= nRanges ? EVERYTHING : scanRanges.getRanges().get(minPos++); KeyRange range = bound == Bound.LOWER ? ranges.get(0) : ranges.get(ranges.size()-1); byte[] b = range.getRange(bound);
if (scanRanges.useSkipScanFilter()) { ScanUtil.andFilterAtBeginning(scan, scanRanges.getSkipScanFilter());
@Test public void test() { ScanRanges scanRanges = ScanRanges.create(schema, Collections.<List<KeyRange>>singletonList(Collections.<KeyRange>singletonList(input)), new int[] {schema.getFieldCount()-1}, null, false, -1); ScanRanges clippedRange = BaseResultIterators.computePrefixScanRanges(scanRanges, clipTo); assertEquals(expectedOutput, clippedRange.getScanRange()); }
private static Collection<?> foreach(ScanRanges scanRanges, int[] widths, KeyRange[] expectedSplits) { SkipScanFilter filter = new SkipScanFilter(scanRanges.getRanges(), buildSchema(widths)); Scan scan = new Scan().setFilter(filter).setStartRow(KeyRange.UNBOUND).setStopRow(KeyRange.UNBOUND); List<Object> ret = Lists.newArrayList(); ret.add(new Object[] {scan, scanRanges, Arrays.<KeyRange>asList(expectedSplits)}); return ret; }
private static void assertIntersect(ScanRanges ranges, String lowerRange, String upperRange, String... expectedPoints) { List<KeyRange> expectedKeys = points(expectedPoints); Collections.sort(expectedKeys,KeyRange.COMPARATOR); Scan scan = new Scan(); scan.setFilter(ranges.getSkipScanFilter()); byte[] startKey = lowerRange == null ? KeyRange.UNBOUND : PVarchar.INSTANCE.toBytes(lowerRange); byte[] stopKey = upperRange == null ? KeyRange.UNBOUND : PVarchar.INSTANCE.toBytes(upperRange); Scan newScan = ranges.intersectScan(scan, startKey, stopKey, 0, true); if (expectedPoints.length == 0) { assertNull(newScan); } else { assertNotNull(newScan); SkipScanFilter filter = (SkipScanFilter)newScan.getFilter(); assertEquals(expectedKeys, filter.getSlots().get(0)); } }
byte[] regionEndKey = entry.getRegion().getEndKey(); if ( ! servers.contains(entry) && keyRanges.intersectRegion(regionStartKey, regionEndKey, cacheUsingTable.getIndexType() == IndexType.LOCAL)) {
boolean isLocalIndex = ScanUtil.isLocalIndex(context.getScan()); boolean forceSkipScan = this.hint.hasHint(Hint.SKIP_SCAN); int nRanges = forceSkipScan ? scanRanges.getRanges().size() : scanRanges.getBoundSlotCount(); for (int i = 0, minPos = 0; minPos < nRanges || minMaxIterator.hasNext(); i++) { List<KeyRange> ranges = minPos >= nRanges ? EVERYTHING : scanRanges.getRanges().get(minPos++); KeyRange range = bound == Bound.LOWER ? ranges.get(0) : ranges.get(ranges.size()-1); byte[] b = range.getRange(bound);
public GettingResultIterator(StatementContext context, Expression where) { this.context = context; this.where = where; this.gets = Lists.newArrayListWithExpectedSize(context.getScanRanges().getPointLookupCount()); Scan scan = context.getScan(); List<List<KeyRange>> ranges = context.getScanRanges().getRanges(); for (KeyRange range : ranges.get(0)) { Get get = new Get(range.getLowerRange()); for (Map.Entry<byte[], NavigableSet<byte[]>> entry : scan.getFamilyMap().entrySet()) { byte[] family = entry.getKey(); if (entry.getValue() != null) { for (byte[] q : entry.getValue()) { get.addColumn(family, q); } } else { get.addFamily(family); } } for (Map.Entry<String, byte[]> attr : scan.getAttributesMap().entrySet()) { get.setAttribute(attr.getKey(), attr.getValue()); } setGetAttribute(get); gets.add(get); } }
public static ScanRanges newScanRanges(List<? extends Mutation> mutations) throws SQLException { List<KeyRange> keys = Lists.newArrayListWithExpectedSize(mutations.size()); for (Mutation m : mutations) { keys.add(PVarbinary.INSTANCE.getKeyRange(m.getRow())); } ScanRanges keyRanges = ScanRanges.createPointLookup(keys); return keyRanges; }