phoenix-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [phoenix] yanxinyi commented on a change in pull request #482: PHOENIX-4925 Use Segment tree to organize Guide Post Info
Date Tue, 30 Apr 2019 02:31:50 GMT
yanxinyi commented on a change in pull request #482: PHOENIX-4925 Use Segment tree to organize
Guide Post Info
URL: https://github.com/apache/phoenix/pull/482#discussion_r279599354
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
 ##########
 @@ -885,292 +867,234 @@ private static boolean clipKeyRangeBytes(RowKeySchema schema, int
fieldIndex, in
         return maxOffset != offset;
     }
 
+    private List<KeyRange> getRowKeyRanges(List<HRegionLocation> regionLocations,
boolean isLocalIndex) {
+        List<KeyRange> queryKeyRanges = null;
+        List<Integer> ignoredRegionList = Lists.newArrayListWithCapacity(regionLocations.size());
+
+        // Use the data plan to build the query row key ranges
+        if (isLocalIndex && dataPlan != null && dataPlan.getTableRef().getTable().getType()
!= PTableType.INDEX) {
+            int columnsInCommon = computeColumnsInCommon();
+            ScanRanges prefixScanRanges = computePrefixScanRanges(dataPlan.getContext().getScanRanges(),
columnsInCommon);
+
+            // Only attempt further pruning if the prefix range is using
+            // a skip scan since we've already pruned the range of regions
+            // based on the start/stop key.
+            if (columnsInCommon > 0 && prefixScanRanges.useSkipScanFilter()) {
+                for (int i = 0; i < regionLocations.size(); i++) {
+                    HRegionInfo regionInfo = regionLocations.get(i).getRegionInfo();
+                    byte[] regionStartKey = regionInfo.getStartKey();
+                    ImmutableBytesWritable ptr = context.getTempPtr();
+                    clipKeyRangeBytes(prefixScanRanges.getSchema(), 0,
+                            columnsInCommon, regionStartKey, ptr, false);
+                    regionStartKey = ByteUtil.copyKeyBytesIfNecessary(ptr);
+                    // Prune this region if there's no intersection
+                    if (! prefixScanRanges.intersectRegion(regionStartKey, regionInfo.getEndKey(),
false)) {
+                        ignoredRegionList.add(i);
+                    }
+                }
+            }
+
+            queryKeyRanges = prefixScanRanges.getRowKeyRanges();
+        }
+
+        if (queryKeyRanges == null) {
+            ScanRanges scanRanges = context.getScanRanges();
+            queryKeyRanges = scanRanges.getRowKeyRanges();
+        }
+
+        // Prepend region ranges to query key regions
+        if (isLocalIndex) {
+            List<KeyRange> newQueryRowKeyRanges = Lists.newArrayListWithExpectedSize(
+                    queryKeyRanges.size() * regionLocations.size());
+
+            int index = 0;
+            for (int i = 0; i < regionLocations.size(); i++) {
+                if (index < ignoredRegionList.size() && ignoredRegionList.get(index)
== i) {
+                    index++;
+                    continue;
+                }
+
+                HRegionInfo regionInfo = regionLocations.get(i).getRegionInfo();
+
+                for (KeyRange queryKeyRange : queryKeyRanges) {
+                    byte[] bytesToPrepend = regionInfo.getStartKey();
+                    int length = bytesToPrepend.length;
+                    if (length == 0) {
+                        length = regionInfo.getEndKey().length;
+                        if (length > 0) {
+                            bytesToPrepend = new byte[length];
+                        }
+                    }
+
+                    KeyRange newQueryRowKeyRange = queryKeyRange.prependRange(
+                            bytesToPrepend, 0, bytesToPrepend.length);
+                    newQueryRowKeyRanges.add(newQueryRowKeyRange);
+                }
+            }
+
+            if (newQueryRowKeyRanges.size() == 0) {
+                newQueryRowKeyRanges.add(KeyRange.EMPTY_RANGE);
+            }
+
+            queryKeyRanges = newQueryRowKeyRanges;
+        }
+
+        return queryKeyRanges;
+    }
+
     /**
      * Compute the list of parallel scans to run for a given query. The inner scans
      * may be concatenated together directly, while the other ones may need to be
-     * merge sorted, depending on the query.
-     * Also computes an estimated bytes scanned, rows scanned, and last update time
-     * of statistics. To compute correctly, we need to handle a couple of edge cases:
-     * 1) if a guidepost is equal to the start key of the scan.
-     * 2) If a guidepost is equal to the end region key.
-     * In both cases, we set a flag (delayAddingEst) which indicates that the previous
-     * gp should be use in our stats calculation. The normal case is that a gp is
-     * encountered which is in the scan range in which case it is simply added to
-     * our calculation.
-     * For the last update time, we use the min timestamp of the gp that are in
-     * range of the scans that will be issued. If we find no gp in the range, we use
-     * the gp in the first or last region of the scan. If we encounter a region with
-     * no gp, then we return a null value as an indication that we don't know with
-     * certainty when the stats were updated last. This handles the case of a split
-     * occurring for a large ingest with stats never having been calculated for the
-     * new region.
+     * merge sorted, depending on the query. Also computes an estimated bytes scanned,
+     * rows scanned, and last update time of statistics.
+     *
      * @return list of parallel scans to run for a given query.
      * @throws SQLException
      */
     private List<List<Scan>> getParallelScans(byte[] startKey, byte[] stopKey)
throws SQLException {
+        ScanRanges scanRanges = context.getScanRanges();
 
 Review comment:
   why we change the order here?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message