You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@polaris.apache.org by "pjanuario (via GitHub)" <gi...@apache.org> on 2026/02/06 14:56:46 UTC

[I] Performance Critical: `create_namespace` Latency (>30s) - Schema & Query Optimization Required [polaris]

pjanuario opened a new issue, #3685:
URL: https://github.com/apache/polaris/issues/3685

   ### Describe the bug
   
   ### **1. Issue Summary**
   
   We are experiencing a critical performance degradation where the `create_namespace` API operation consistently times out (>30s), causing cascading failures in our downstream workload infrastructure (Traefik 504 Gateway Timeouts and pyiceberg have an unexpected behaviour).
   
   ### **2. Remediation Status**
   
   To restore production stability, we are manually applying the following schema changes:
   
   * **Applied:** `idx_entities_catalog_id_id` on `entities`. (Result: Latency dropped from ~36s to ~17s).
   * **Applying Now:** `idx_grants_realm_grantee` and `idx_grants_realm_securable` on `grant_records` to resolve 100% CPU usage during permission checks and GC.
   
   ### **3. Root Cause Analysis (Database Layer)**
   
   Our investigation confirmed that the default schema lacks secondary indexes required for the application's actual query patterns.
   
   **A. The "Grant Records" Bottleneck (High Frequency)**
   The application performs thousands of permission checks per operation.
   
   * **Observation:** 100% Sequential Scans.
   * **Metrics:** 65,000+ executions of `SELECT ... WHERE grantee_id = ...`.
   * **Impact:** Without an index starting with `grantee_id` or `realm_id`, the database reads **13.7 Billion rows** to serve these requests.
   * **Fix:** We are adding indexes to support lookups by `grantee_id` and `securable_id`.
   
   **B. The "Entities" Bottleneck (Bulk Fetch)**
   
   * **Observation:** Namespace create operation triggers a query with a massive `IN` clause containing ~7,800 tuples: `WHERE (catalog_id, id) IN ((?,?), (?,?)...)`.
   * **Impact:** The query planner could not use the PK (starting with `realm_id`) efficiently, resulting in 17s+ execution time.
   * **Fix:** We added `idx_entities_catalog_id_id` to optimize this lookup.
   
   ### **4. Request for Engineering: Query Optimization**
   
   While the indexes mitigate the immediate outage, the underlying query patterns appear inefficient and likely need refactoring in the Polaris codebase.
   
   **1. Review "N+1" Permission Checks**
   We observed **65,415 executions** of the permission check query during a short window.
   
   * *Question:* Is the application iterating through a list and checking permissions one-by-one instead of performing a bulk permission check? This volume suggests an "N+1" query issue that indexes can only partially band-aid.
   
   **2. Review Bulk Entity Fetch Strategy**
   The query `SELECT ... FROM entities WHERE (catalog_id, id) IN (...)` is passing **~15,000 bind parameters** (7,800 pairs).
   
   * *Recommendation:* This pattern scales poorly. Please consider paginating this operation or refactoring the logic to avoid passing thousands of IDs in a single SQL statement.
   
   ### **5. SQL for Upstream Merge**
   
   We strongly recommend including these indexes in the next Polaris release to prevent similar degradation for other users:
   
   ```sql
   -- 1. Optimizes High-Volume Permission Checks (Fixes API CPU load)
   CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_grants_realm_grantee 
   ON polaris_schema.grant_records (realm_id, grantee_id);
   
   -- 2. Optimizes Garbage Collection (Fixes background job hangs)
   CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_grants_realm_securable 
   ON polaris_schema.grant_records (realm_id, securable_id);
   
   -- 3. Optimizes Bulk Entity Lookups (Fixes Namespace listing latency)
   CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_entities_catalog_id_id 
   ON polaris_schema.entities (catalog_id, id);
   
   ```
   
   ### To Reproduce
   
   1. **Environment:** Deploy Apache Polaris backed by PostgreSQL with a moderate dataset (~170k grant records, ~160k entities).
   2. **Action:** Execute the `create_namespace` API operation on a catalog with ~22k namespaces.
   3. **Conditions:** Ensure standard concurrency; the issue manifests even without much load due to table scans.
   4. **Observation:** Monitor API response time and database activity via `pg_stat_statements`.
   
   
   ### Actual Behavior
   
   * **Performance:** The operation consistently takes **33s - 36s** to complete.
   * **Database Execution:** Permission checks trigger a **Sequential Scan** of the entire `grant_records` table for every single lookup. We observed queries reading **~174,000 rows per execution** (100% of the table) thousands of times per minute.
   * **Client Experience:** The API request times out. Proxies (e.g., Traefik) return `504 Gateway Timeout` at the 30s mark, and client applications (crawlers) hang or fail silently.
   
   ### Expected Behavior
   
   * **Performance:** The `create_namespace` operation should complete in **sub-second time to ~2 seconds**.
   * **Database Execution:** Permission checks filtering by `grantee_id` should utilize an **Index Scan**, reading only the specific rows relevant to the user (typically <100 rows).
   * **Client Experience:** The request should return `200 OK` well within standard proxy/client timeout windows (30s).
   
   ### Additional context
   
   All this information was very consistent along the research we did, after applying the first index `idx_entities_catalog_id_id` we seen a consistent drop on the response time from ~31s into ~16s.
   After the index was applied the stats were reset and and pg statements cleaned, we kept the system running for +-24h and the data we see in the ticket is from this period after the resets.
   
   ### System information
   
   OS: Linux
   Polaris Catalog Version: Docker image 1.3.0 (initial symptoms were present in 1.0.1 and we upgraded to validate if this was caused by the version, the problem persisted)
   Object storage & setup: AWS S3


-- 
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: issues-unsubscribe@polaris.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Performance Critical: `create_namespace` Latency (>30s) - Schema & Query Optimization Required [polaris]

Posted by "pjanuario (via GitHub)" <gi...@apache.org>.
pjanuario commented on issue #3685:
URL: https://github.com/apache/polaris/issues/3685#issuecomment-3860923178

   I have discussed this with @jbonofre on slack.
   Keep in mind that I looked at this problem from the database angle as I have very low knowledge of the application codebase.


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Performance Critical: `create_namespace` Latency (>30s) - Schema & Query Optimization Required [polaris]

Posted by "pjanuario (via GitHub)" <gi...@apache.org>.
pjanuario commented on issue #3685:
URL: https://github.com/apache/polaris/issues/3685#issuecomment-3877046015

   > * number of principals
   > * number of catalog roles
   > * number of principal roles
   > * number of privileges assigned per entity to roles
   
   number of catalogs: 82
   number of principals: 5
   number of catalog roles: 2 per catalog + default catalog admin
   number of principal roles: 3 + service admin (one of the principals have a role in all catalogs)
   number of privileges assigned per entity to roles: each catalog owner role have 2 grants
   


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Performance Critical: `create_namespace` Latency (>30s) - Schema & Query Optimization Required [polaris]

Posted by "pjanuario (via GitHub)" <gi...@apache.org>.
pjanuario commented on issue #3685:
URL: https://github.com/apache/polaris/issues/3685#issuecomment-3876980130

   FYI, just reinforcing, although that applying the indexes reduced the operation to 50% of the response, this unblocked us on the of the workloads (with 11k namespaces) but not the other one with (26k namespaces).
   I think the main culprit is this as the database can't create a decent query plan and this would also show a correlation between the number of namespaces and the tuples.
   
   > Observation: Namespace create operation triggers a query with a massive IN clause containing ~7,800 tuples: WHERE (catalog_id, id) IN ((?,?), (?,?)...)


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Performance Critical: `create_namespace` Latency (>30s) - Schema & Query Optimization Required [polaris]

Posted by "pjanuario (via GitHub)" <gi...@apache.org>.
pjanuario commented on issue #3685:
URL: https://github.com/apache/polaris/issues/3685#issuecomment-3861826995

   I wasn't clear to me how the schemas were being managed or I would have opened a PR. Regarding the application changes, that's likely require a bit more effort.


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Performance Critical: `create_namespace` Latency (>30s) - Schema & Query Optimization Required [polaris]

Posted by "pingtimeout (via GitHub)" <gi...@apache.org>.
pingtimeout commented on issue #3685:
URL: https://github.com/apache/polaris/issues/3685#issuecomment-3876840364

   @MonkeyCanCode Yes, definitely.  I should be able to work on that next week.  I can see how benchmarks can be evolved to include arbitrary numbers of principals/roles/privileges.
   
   @pjanuario by any chance, could you describe a little bit your specific RBAC implementation?  I am thinking an approximation of:
   * number of principals
   * number of catalog roles
   * number of principal roles
   * number of privileges assigned per entity to roles
   
   This would give very valuable information to replicate a real-world scenario.


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Performance Critical: `create_namespace` Latency (>30s) - Schema & Query Optimization Required [polaris]

Posted by "snazy (via GitHub)" <gi...@apache.org>.
snazy commented on issue #3685:
URL: https://github.com/apache/polaris/issues/3685#issuecomment-3861015428

   Thanks a lot @pjanuario for the report!
   The numbers you mention, even with the indexes, are indeed very concerning.
   
   Good that there is some improvement with the indexes, which look reasonable to add to me BTW.
   Considering that it's not much of an effort to add these indexes (it's a "dumb" text file with SQL statements), those should be added in 1.4.0.


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Performance Critical: `create_namespace` Latency (>30s) - Schema & Query Optimization Required [polaris]

Posted by "pjanuario (via GitHub)" <gi...@apache.org>.
pjanuario commented on issue #3685:
URL: https://github.com/apache/polaris/issues/3685#issuecomment-3877288578

   Another note that might be unrelated but i noticed the following:
   
   ```
   2026-02-09 21:59:19.9012026-02-09 21:59:19,901 INFO  [io.qua.htt.access-log] [99ad2e01-8bb9-4d78-9595-56414ee70fb3_0000000000000226626,BASELIGHT] [,,,] (vert.x-eventloop-thread-13) 172.18.X.X - X [09/Feb/2026:21:59:19 +0000] "POST /api/catalog/v1/zzz/namespaces HTTP/1.1" 200 -
   2026-02-09 20:46:57.4452026-02-09 20:46:57,444 INFO  [io.qua.htt.access-log] [99ad2e01-8bb9-4d78-9595-56414ee70fb3_0000000000000218606,BASELIGHT] [,,,] (executor-thread-744) 172.18.X.X - X [09/Feb/2026:20:46:57 +0000] "POST /api/catalog/v1/zzz/namespaces/zzz/tables/zz HTTP/1.1" 200 4374
   ```
   
   As on the problematic logs we  see a `200` status code without any content length and `vert.x-eventloop-thread-0` while on the others we have `200` and the content legnth and different thread name `executor-thread-744`.  I wonder if there is anything going on and this request is made on the event loop thread instead of a worker thread, as I would expect the same behaviour for both operations.
   


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Performance Critical: `create_namespace` Latency (>30s) - Schema & Query Optimization Required [polaris]

Posted by "pjanuario (via GitHub)" <gi...@apache.org>.
pjanuario commented on issue #3685:
URL: https://github.com/apache/polaris/issues/3685#issuecomment-3884582215

   @snazy thanks the thorough explanation, FYI, we had to disable iceberg on 2 of our catalogs (the ones mentioned) as this was impacting our workload due to the ability to manage the namespace and reducing data availability, for now this data will only be made available on our internal catalog implementation thats runs in parallel with Polaris. Let me know if I can assist in some form.


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Performance Critical: `create_namespace` Latency (>30s) - Schema & Query Optimization Required [polaris]

Posted by "pjanuario (via GitHub)" <gi...@apache.org>.
pjanuario commented on issue #3685:
URL: https://github.com/apache/polaris/issues/3685#issuecomment-3876957078

   This is our scaffolding logging for every knew catalog we create, i hope it helps:
   ```
   Creating principal role...
   Principal role 'public_catalog_reader' already exists. Skipping creation.
   Setting up catalogs...
   Creating principal X...
   Principal 'X' already exists. Skipping creation.
   Creating principal role x_role...
   Principal role 'x_role' already exists. Skipping creation.
   Principal 'X' already has 'public_catalog_reader' role. Skipping association.
   Creating landing zone for user catalog: Y...
   Creating catalog roles for Y...
   Creating catalog role catalog_owner for Y...
   Creating catalog role catalog_reader for Y...
   Skipping principal creation for Y.
   Landing zone for catalog 'Y' created successfully.
   Catalog 'Y' created successfully.
   ```
   
   At the moments we only use a few principals (5 at the moment), that's why you see X and x_role being skipped as they were created on previous executions, but the RBAC is configured so that we can specific roles per catalog.
   
   So, each: 
   * catalog have 2 roles (catalog read and catalog owner)
   * principal have the public catalog reader (means it as catalog reader on all catalogs) and (may multiple catalog owner)
   
   


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Performance Critical: `create_namespace` Latency (>30s) - Schema & Query Optimization Required [polaris]

Posted by "pingtimeout (via GitHub)" <gi...@apache.org>.
pingtimeout commented on issue #3685:
URL: https://github.com/apache/polaris/issues/3685#issuecomment-3927760810

   I have updated the Polaris benchmarks to include the creation of RBAC entities as part of the dataset creation workload (https://github.com/apache/polaris-tools/pull/173/).  I was not able to reproduce a 30s namespace creation response time, but I could certainly see that the table and view creations duration increased linearly with the amount of namespaces and grants (see chart below for table creation response time vs. time)
   
   <img width="2046" height="760" alt="Image" src="https://github.com/user-attachments/assets/a3b1608c-070e-4ff4-8f6b-5c95fd59399c" />
   
   Attached is a PG dump with the database state in case anybody want to replicate the issue without creating a dataset from scratch.
   
   [polaris_backup_20260219_145616.sql.gz](https://github.com/user-attachments/files/25418883/polaris_backup_20260219_145616.sql.gz).
   
   Repro steps otherwise:
   1. Clone the branch for https://github.com/apache/polaris-tools/pull/173/ (until it is merged)
   2. Create an `application.conf` file and direct it to your Polaris server
   3. Add section below to `application.conf`
   4. Run the write benchmark
   
   ```
   rbac {
     enabled = true
     num-principals = 5
     catalog-role-names = ["catalog_reader", "catalog_contributor"]
     principal-role-names = ["data_engineer", "data_scientist"]
   }
   ```


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Performance Critical: `create_namespace` Latency (>30s) - Schema & Query Optimization Required [polaris]

Posted by "pjanuario (via GitHub)" <gi...@apache.org>.
pjanuario commented on issue #3685:
URL: https://github.com/apache/polaris/issues/3685#issuecomment-3862006978

   I didn't see any instruction in the upgrade documentation to execute migrations or DDL and my though was that bootstrap is used on to create a new instance, could it be that I am missing something and schema is not at latest versions as it should?
   
   Adding in the counters for each table
   
   ```
   polaris=# select count(*) from entities;
    count
   --------
    167637
   (1 row)
   
   polaris=# select count(*) from grant_records;
    count
   --------
    176103
   (1 row)
   
   polaris=# select count(*) from policy_mapping_record;
    count
   -------
        0
   (1 row)
   
   polaris=# select count(*) from principal_authentication_data;
    count
   -------
        5
   (1 row)
   ```


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Performance Critical: `create_namespace` Latency (>30s) - Schema & Query Optimization Required [polaris]

Posted by "jbonofre (via GitHub)" <gi...@apache.org>.
jbonofre commented on issue #3685:
URL: https://github.com/apache/polaris/issues/3685#issuecomment-3877567904

   As discussed on Slack, it would be great to have a thread dump. In the meantime, thanks for the numbers, we can try to reproduce something similar (as it's complicated to have a pg dump).


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Performance Critical: `create_namespace` Latency (>30s) - Schema & Query Optimization Required [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on issue #3685:
URL: https://github.com/apache/polaris/issues/3685#issuecomment-3861839246

   > how the schemas were being managed [...]
   
   The [Admin Tool](https://github.com/apache/polaris/tree/main/runtime/admin)'s `bootstrap` command should be able to allow the selected schema idempotently.


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Performance Critical: `create_namespace` Latency (>30s) - Schema & Query Optimization Required [polaris]

Posted by "MonkeyCanCode (via GitHub)" <gi...@apache.org>.
MonkeyCanCode commented on issue #3685:
URL: https://github.com/apache/polaris/issues/3685#issuecomment-3875485604

   @pingtimeout maybe something we should add for benchmark tool?


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Performance Critical: `create_namespace` Latency (>30s) - Schema & Query Optimization Required [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on issue #3685:
URL: https://github.com/apache/polaris/issues/3685#issuecomment-3937797053

   It looks like we do not have any fix in progress for this yet, but the 1.4.0 release imminent... I'm going to move this to the next milestone.


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Performance Critical: `create_namespace` Latency (>30s) - Schema & Query Optimization Required [polaris]

Posted by "adnanhemani (via GitHub)" <gi...@apache.org>.
adnanhemani closed issue #3685: Performance Critical: `create_namespace` Latency (>30s) - Schema & Query Optimization Required
URL: https://github.com/apache/polaris/issues/3685


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Performance Critical: `create_namespace` Latency (>30s) - Schema & Query Optimization Required [polaris]

Posted by "snazy (via GitHub)" <gi...@apache.org>.
snazy commented on issue #3685:
URL: https://github.com/apache/polaris/issues/3685#issuecomment-3879497770

   >  I wonder if there is anything going on and this request is made on the event loop thread instead of a worker thread, as I would expect the same behaviour for both operations.
   
   I wouldn't worry much about the thread name that's been logged. I assume ([asked for confirmation](https://quarkusio.zulipchat.com/#narrow/channel/187038-dev/topic/Thread.20logged.20in.20HTTP.20access-log/with/573098838)) that this is just the thread that logs the message, which does not need to be the same thread that executed the [blocking request](https://quarkus.io/guides/rest#execution-model).
   The actual logging is basically just one of the last "actions" that run during the whole HTTP request processing.
   All REST API requests in Polaris are blocking requests, as the OpenAPI generation tool does not allow us to use a async/reactive programming model.
   The thread name in the access log would become even less meaningful for async/reactive requests.
   It's not the case that all "parts" (core HTTP "machinery", authZ, etc) involved in processing a single HTTP request run synchronously on a single thread, not even for blocking request.


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org