devmadhuu commented on code in PR #9258:
URL: https://github.com/apache/ozone/pull/9258#discussion_r2905984491


##########
hadoop-ozone/recon-codegen/src/main/java/org/apache/ozone/recon/schema/ContainerSchemaDefinition.java:
##########
@@ -80,8 +80,24 @@ private void createUnhealthyContainersTable() {
             .check(field(name(CONTAINER_STATE))
                 .in(UnHealthyContainerStates.values())))
         .execute();
-    dslContext.createIndex("idx_container_state")
-        .on(DSL.table(UNHEALTHY_CONTAINERS_TABLE_NAME), 
DSL.field(name(CONTAINER_STATE)))
+    // Composite index (container_state, container_id) serves two query 
patterns:
+    //
+    // 1. COUNT(*)/GROUP-BY filtered by state:
+    //      WHERE container_state = ?
+    //    Derby uses the index prefix (container_state) — same efficiency as 
the old
+    //    single-column idx_container_state.
+    //
+    // 2. Paginated reads filtered by state + cursor:
+    //      WHERE container_state = ? AND container_id > ? ORDER BY 
container_id ASC
+    //    With the old single-column index Derby had to:
+    //      a) Scan ALL rows for the state (e.g. 200K), then
+    //      b) Sort them by container_id for every page call — O(n) per page.
+    //    With this composite index Derby jumps directly to (state, minId) and 
reads
+    //    the next LIMIT entries sequentially — O(1) per page, ~10–14× faster.
+    dslContext.createIndex("idx_state_container_id")
+        .on(DSL.table(UNHEALTHY_CONTAINERS_TABLE_NAME),
+            DSL.field(name(CONTAINER_STATE)),
+            DSL.field(name(CONTAINER_ID)))

Review Comment:
   Handled using new upgrade action.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to