This is an automated email from the ASF dual-hosted git repository.

palashc pushed a commit to branch 5.3
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/5.3 by this push:
     new d160b9e8d1 PHOENIX-7772 : Fix NPE in TOTAL_SEGMENTS query when table 
has index (#2382) (#2383)
d160b9e8d1 is described below

commit d160b9e8d1cb1793a51c422bb9e1a246272aac8d
Author: Palash Chauhan <[email protected]>
AuthorDate: Fri Feb 20 17:00:36 2026 -0800

    PHOENIX-7772 : Fix NPE in TOTAL_SEGMENTS query when table has index (#2382) 
(#2383)
    
    Co-authored-by: Palash Chauhan 
<[email protected]>
---
 .../org/apache/phoenix/execute/SegmentInfoPlan.java     |  7 +++++++
 .../phoenix/end2end/BaseTotalSegmentsFunctionIT.java    | 17 ++++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git 
a/phoenix-core-client/src/main/java/org/apache/phoenix/execute/SegmentInfoPlan.java
 
b/phoenix-core-client/src/main/java/org/apache/phoenix/execute/SegmentInfoPlan.java
index 79134600a2..92f9e071d2 100644
--- 
a/phoenix-core-client/src/main/java/org/apache/phoenix/execute/SegmentInfoPlan.java
+++ 
b/phoenix-core-client/src/main/java/org/apache/phoenix/execute/SegmentInfoPlan.java
@@ -65,6 +65,13 @@ public class SegmentInfoPlan extends ClientProcessingPlan {
     return true;
   }
 
+  @Override
+  public boolean isDegenerate() {
+    // return true so that optimizer can choose this plan over any index plan 
and return early if
+    // the table has indexes.
+    return true;
+  }
+
   @Override
   public ResultIterator iterator(ParallelScanGrouper scanGrouper, Scan scan) 
throws SQLException {
     ConnectionQueryServices services = 
context.getConnection().getQueryServices();
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseTotalSegmentsFunctionIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseTotalSegmentsFunctionIT.java
index 2043b57783..044dd2ea8a 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseTotalSegmentsFunctionIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseTotalSegmentsFunctionIT.java
@@ -72,7 +72,16 @@ public abstract class BaseTotalSegmentsFunctionIT extends 
ParallelStatsDisabledI
   protected abstract String extractPrimaryKeyValue(ResultSet rs) throws 
SQLException;
 
   @Test
-  public void testTotalSegmentsWithSimpleTable() throws Exception {
+  public void testTotalSegmentsWithSimpleTableWithIndex() throws Exception {
+    testTotalSegmentsWithSimpleTable(true);
+  }
+
+  @Test
+  public void testTotalSegmentsWithSimpleTableWithoutIndex() throws Exception {
+    testTotalSegmentsWithSimpleTable(false);
+  }
+
+  public void testTotalSegmentsWithSimpleTable(boolean hasIndex) throws 
Exception {
     Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
 
     try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
@@ -82,6 +91,12 @@ public abstract class BaseTotalSegmentsFunctionIT extends 
ParallelStatsDisabledI
 
       conn.createStatement().execute(createSql);
 
+      if (hasIndex) {
+        String indexName = generateUniqueName();
+        conn.createStatement()
+          .execute("CREATE INDEX " + indexName + " ON " + fullTableName + " 
(V1)");
+      }
+
       // Get actual regions from ConnectionQueryServices
       PhoenixConnection phoenixConn = conn.unwrap(PhoenixConnection.class);
       ConnectionQueryServices services = phoenixConn.getQueryServices();

Reply via email to