[ 
https://issues.apache.org/jira/browse/PHOENIX-6907?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17738844#comment-17738844
 ] 

ASF GitHub Bot commented on PHOENIX-6907:
-----------------------------------------

jpisaac commented on code in PR #1598:
URL: https://github.com/apache/phoenix/pull/1598#discussion_r1247322349


##########
phoenix-core/src/main/java/org/apache/phoenix/iterate/ExplainTable.java:
##########
@@ -111,8 +126,63 @@ private String explainSkipScan() {
         return buf.toString();
     }
 
-    protected void explain(String prefix, List<String> planSteps,
-            ExplainPlanAttributesBuilder explainPlanAttributesBuilder) {
+    /**
+     * Get regions that represent the given range of start and end key for the 
given table, and
+     * all the regions to the regionLocations list.
+     *
+     * @param tableName the table name.
+     * @param startKey the start rowkey.
+     * @param endKey the end rowkey.
+     * @param includeEndKey true if end key needs to be included.
+     * @param reload true if reload from meta is necessary.
+     * @param regionBoundaries set of region boundaries to get the unique list 
of region locations.
+     * @param regionLocations the list of region locations as output.
+     * @throws IOException if something goes wrong while creating connection 
or querying region
+     * locations.
+     */
+    private void getRegionsInRange(final byte[] tableName,
+                                   final byte[] startKey,
+                                   final byte[] endKey,
+                                   final boolean includeEndKey,
+                                   final boolean reload,
+                                   Set<RegionBoundary> regionBoundaries,
+                                   List<HRegionLocation> regionLocations)
+            throws IOException, SQLException {
+        final boolean endKeyIsEndOfTable = Bytes.equals(endKey, 
HConstants.EMPTY_END_ROW);
+        if ((Bytes.compareTo(startKey, endKey) > 0) && !endKeyIsEndOfTable) {
+            throw new IllegalArgumentException(
+                    "Invalid range: " + Bytes.toStringBinary(startKey) + " > " 
+
+                            Bytes.toStringBinary(endKey));
+        }
+        byte[] currentKey = startKey;
+        try (Table table = 
context.getConnection().getQueryServices().getTable(tableName)) {
+            do {
+                HRegionLocation regionLocation =
+                        table.getRegionLocator().getRegionLocation(currentKey, 
reload);
+                RegionBoundary regionBoundary =
+                        new 
RegionBoundary(regionLocation.getRegion().getStartKey(),
+                                regionLocation.getRegion().getEndKey());
+                if (!regionBoundaries.contains(regionBoundary)) {
+                    regionLocations.add(regionLocation);
+                    regionBoundaries.add(regionBoundary);
+                }
+                currentKey = regionLocation.getRegion().getEndKey();
+                // condition1 = currentKey != END_ROW_KEY
+                // condition2 = endKeyIsEndOfTable == true
+                // condition3 = currentKey < endKey
+                // condition4 = includeEndKey == true
+                // condition5 = currentKey == endKey
+                // while (condition1 && (condition2 || condition3 || 
(condition4 && condition5)))

Review Comment:
   nit: Might be easier on the reader if it is in plain layman's language





> Explain Plan should output region locations with servers
> --------------------------------------------------------
>
>                 Key: PHOENIX-6907
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-6907
>             Project: Phoenix
>          Issue Type: Improvement
>            Reporter: Viraj Jasani
>            Assignee: Viraj Jasani
>            Priority: Major
>             Fix For: 5.2.0, 5.1.4
>
>
> As of today, explain plan provides details related to scan key range size, 
> size of the scan lists (for parallel scans), hints, client/server sorted by, 
> order by, server filter etc. It provides as much close details to the 
> physical plans as possible.
> If we could also make explain plan output to include region locations that 
> also contains regionserver details on which the region is currently residing, 
> this might turn out to be really good insights. For full table scans, this 
> also means that we would end up including very higher number of region 
> locations and it would not be ideal to print all of them in the output. We 
> can enforce a limit on the num of region locations to print (default value 
> could be 10 or so). For point lookup and range scans, we can find the region 
> locations with regionserver as quite useful for the real time analysis of 
> slowness experienced by the given query.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to