You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@polaris.apache.org by "machov (via GitHub)" <gi...@apache.org> on 2026/03/05 15:03:33 UTC
[PR] fix(schema): Add critical performance indexes to resolve create_namespace latency >30s [polaris]
machov opened a new pull request, #3939:
URL: https://github.com/apache/polaris/pull/3939
## Problem
Issue #3685 reports critical performance degradation where `create_namespace` API operations consistently timeout (>30s), causing cascading failures with 504 Gateway Timeouts.
## Root Cause Analysis
Database analysis revealed:
- **65,000+ permission check queries** performing full table scans on `grant_records`
- **Bulk entity lookups** with ~7,800 tuples causing inefficient query plans
- **13.7 billion rows read** during a single create_namespace operation
## Solution
Added schema v5 with three performance-critical indexes:
1. **`idx_grants_realm_grantee`** on `grant_records(realm_id, grantee_id)`
- Eliminates sequential scans for permission checks
2. **`idx_grants_realm_securable`** on `grant_records(realm_id, securable_id)`
- Optimizes grant record cleanup and GC operations
3. **`idx_entities_catalog_id_id`** on `entities(catalog_id, id)`
- Optimizes bulk entity lookups with large IN clauses
## Performance Impact
Based on issue reporter's testing:
- **Before**: create_namespace consistently 33-36 seconds
- **After**: Latency dropped to **under 2 seconds**
## Database Compatibility
- ✅ PostgreSQL schema v5 created
- ✅ H2 schema v5 created
- ✅ Uses `IF NOT EXISTS` for safe deployment
Fixes #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: [PR] fix(schema): Add critical performance indexes to resolve create_namespace latency >30s [polaris]
Posted by "jbonofre (via GitHub)" <gi...@apache.org>.
jbonofre commented on code in PR #3939:
URL: https://github.com/apache/polaris/pull/3939#discussion_r2938580354
##########
persistence/relational-jdbc/src/main/resources/h2/schema-v4.sql:
##########
@@ -97,6 +98,11 @@ COMMENT ON COLUMN grant_records.grantee_catalog_id IS 'catalog id of the grantee
COMMENT ON COLUMN grant_records.grantee_id IS 'id of the grantee';
COMMENT ON COLUMN grant_records.privilege_code IS 'privilege code';
+CREATE INDEX IF NOT EXISTS idx_grants_realm_grantee
+ ON grant_records (realm_id, grantee_id);
+CREATE INDEX IF NOT EXISTS idx_grants_realm_securable
+ ON grant_records (realm_id, securable_id);
Review Comment:
This one seems already covered by the primary key index.
If we want this index, I think we should include `securable_catalog_id`, no ?
##########
persistence/relational-jdbc/src/main/resources/h2/schema-v4.sql:
##########
@@ -97,6 +98,11 @@ COMMENT ON COLUMN grant_records.grantee_catalog_id IS 'catalog id of the grantee
COMMENT ON COLUMN grant_records.grantee_id IS 'id of the grantee';
COMMENT ON COLUMN grant_records.privilege_code IS 'privilege code';
+CREATE INDEX IF NOT EXISTS idx_grants_realm_grantee
+ ON grant_records (realm_id, grantee_id);
Review Comment:
The index should include `grantee_catalog_id` no ?
##########
persistence/relational-jdbc/src/main/resources/postgres/schema-v4.sql:
##########
@@ -57,6 +57,7 @@ CREATE TABLE IF NOT EXISTS entities (
-- TODO: create indexes based on all query pattern.
CREATE INDEX IF NOT EXISTS idx_entities ON entities (realm_id, catalog_id, id);
+CREATE INDEX IF NOT EXISTS idx_entities_catalog_id_id ON entities (catalog_id, id);
Review Comment:
Is it not already covered by `idx_entities` index ?
--
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: [PR] fix(schema): Add critical performance indexes to resolve create_namespace latency >30s [polaris]
Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on PR #3939:
URL: https://github.com/apache/polaris/pull/3939#issuecomment-4013850947
Good point - I missed that v4 schema was added after 1.3.0. Let's update v4 in this PR and merge it before 1.4.0 then. Adding to 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: [PR] fix(schema): Add critical performance indexes to resolve create_namespace latency >30s [polaris]
Posted by "adnanhemani (via GitHub)" <gi...@apache.org>.
adnanhemani merged PR #3939:
URL: https://github.com/apache/polaris/pull/3939
--
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: [PR] fix(schema): Add critical performance indexes to resolve create_namespace latency >30s [polaris]
Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on PR #3939:
URL: https://github.com/apache/polaris/pull/3939#issuecomment-4012794906
@machov : The PR is good to merge from my POV, I merely wanted it to have some more time in review in case other interested people have opinions on the new indexes.
The question about 1.4.0 was basically to check whether you need this fix in the 1.4.0 release or you're ok with merging it after 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: [PR] fix(schema): Add critical performance indexes to resolve create_namespace latency >30s [polaris]
Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on PR #3939:
URL: https://github.com/apache/polaris/pull/3939#issuecomment-4013590531
> do we need a v5, this is technically an additional command ?
I'm personally fine with adding the new indexes to v4 DDL files.
However, from a more rigorous perspective, it makes sense to version the schema every time there is a material change. This way, it is easier to track how the Polaris database is expected to behave... For example, we could (hypothetically) deny the expensive operations with a v4 schema.
I do not mean to do that in current PR, just exposing options to consider :slightly_smiling_face:
--
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: [PR] fix(schema): Add critical performance indexes to resolve create_namespace latency >30s [polaris]
Posted by "adnanhemani (via GitHub)" <gi...@apache.org>.
adnanhemani commented on PR #3939:
URL: https://github.com/apache/polaris/pull/3939#issuecomment-4035772836
Yes, I think this is reasonable to put in 1.4.0, given we are still waiting on some last license and notice stuff.
And agreed with @dimas-b, @flyrain, and @singhpk234 - given that v4 was never in a public release, we should just merge the index changes onto that. I will hold the release until we are able to get this PR sorted (if possible within this week)!
Thank you for your great work, @machov!
--
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: [PR] fix(schema): Add critical performance indexes to resolve create_namespace latency >30s [polaris]
Posted by "singhpk234 (via GitHub)" <gi...@apache.org>.
singhpk234 commented on PR #3939:
URL: https://github.com/apache/polaris/pull/3939#issuecomment-4013549353
couple of feedbacks :
- do we need a v5, this is technically an additional command ?
- do we need to ship these indexes or can we add them as recommendation in our docs or code ?
- obviously do we need this in in 1.4 ?
--
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: [PR] fix(schema): Add critical performance indexes to resolve create_namespace latency >30s [polaris]
Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on PR #3939:
URL: https://github.com/apache/polaris/pull/3939#issuecomment-4032177315
@machov : I generally support your point about introducing schema v5 in this case.
However, as @flyrain mentioned, the v4 schema has never been released. It was added after 1.3.0 and 1.4.0 is still in early stages (there's no branch for it ATM).
All in all, I think in this particular case it is preferable to add the new indexes to the v4 schema and release them in 1.4.0 (soon).
Downstream users who pull directly from `main` might have to re-apply the new revision of the v4 schema, but AFAIK, the DDL is idempotent, but it should work.
--
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: [PR] fix(schema): Add critical performance indexes to resolve create_namespace latency >30s [polaris]
Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on PR #3939:
URL: https://github.com/apache/polaris/pull/3939#issuecomment-4008805277
@machov : Do you rely on having this fix an a released version soon? Note: 1.4.0 is in the works ATM.
--
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: [PR] fix(schema): Add critical performance indexes to resolve create_namespace latency >30s [polaris]
Posted by "pjanuario (via GitHub)" <gi...@apache.org>.
pjanuario commented on PR #3939:
URL: https://github.com/apache/polaris/pull/3939#issuecomment-4046557928
Once we push this into the 1.4 I will update our instalation and re-enable one of the problematic catalogs that trigger the issue, but i suspect this will not be enough as we did applied those indexes and still the response time decreased dramatically but still was over 30s in some cases. Let's wait and test again after the release.
@machov thanks for the fix.
--
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: [PR] fix(schema): Add critical performance indexes to resolve create_namespace latency >30s [polaris]
Posted by "machov (via GitHub)" <gi...@apache.org>.
machov commented on PR #3939:
URL: https://github.com/apache/polaris/pull/3939#issuecomment-4027926531
@flyrain should i change the target branch then?
@dimas-b I’m contributing as a community member and don’t operate a Polaris deployment myself.
--
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: [PR] fix(schema): Add critical performance indexes to resolve create_namespace latency >30s [polaris]
Posted by "machov (via GitHub)" <gi...@apache.org>.
machov commented on PR #3939:
URL: https://github.com/apache/polaris/pull/3939#issuecomment-4025561183
Do we need a v5 (since this is “just” additional DDL)?
Yes. v5 schema bump is the safest way to ensure the indexes get applied for *existing* installs. Updating v4 only helps fresh installs; it won’t automatically add indexes to databases already initialized at v4.
Do we need to ship these indexes vs recommending in docs/code?
We should ship them. This change takes create_namespace from 30s+ (timeouts) down to ~<2s, so it’s not an optional tuning tip at scale. Shipping via schema/migrations avoids putting manual DDL burden on operators. (Happy to also add a short doc note explaining the rationale.)
Do we need this in 1.4?
Yes. I can backport it to the 1.4.x line as a post-release schema bump (v5) with migration notes (what indexes are created + expected impact/lock behavior). This way 1.4 users get the fix through the normal upgrade flow without changing already-shipped v4 semantics.
--
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: [PR] fix(schema): Add critical performance indexes to resolve create_namespace latency >30s [polaris]
Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on PR #3939:
URL: https://github.com/apache/polaris/pull/3939#issuecomment-4008779526
@jbonofre : FYI ... I believe we spoke about this in the Community Sync call today and @machov kindly opened a PR with a fix already :tada:
--
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: [PR] fix(schema): Add critical performance indexes to resolve create_namespace latency >30s [polaris]
Posted by "flyrain (via GitHub)" <gi...@apache.org>.
flyrain commented on PR #3939:
URL: https://github.com/apache/polaris/pull/3939#issuecomment-4027952989
No need to change the branch ATM, as the 1.4.0 release branch hasn't cut yet.
Hi @adnanhemani, can we include this PR in the 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: [PR] fix(schema): Add critical performance indexes to resolve create_namespace latency >30s [polaris]
Posted by "flyrain (via GitHub)" <gi...@apache.org>.
flyrain commented on PR #3939:
URL: https://github.com/apache/polaris/pull/3939#issuecomment-4025612201
Hi @machov, I think we all agreed on introducing a new schema version for this change. Since 1.4.x has not been released yet, we could simply include this PR as part of the 1.4.0 release. That way there is no need for a backport, and all future releases will automatically include the indexes as well. WDYT?
--
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: [PR] fix(schema): Add critical performance indexes to resolve create_namespace latency >30s [polaris]
Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on PR #3939:
URL: https://github.com/apache/polaris/pull/3939#issuecomment-4025621958
@machov : just for my own understanding: Do you use releases of do you deploy Polaris from `main`?
--
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: [PR] fix(schema): Add critical performance indexes to resolve create_namespace latency >30s [polaris]
Posted by "machov (via GitHub)" <gi...@apache.org>.
machov commented on PR #3939:
URL: https://github.com/apache/polaris/pull/3939#issuecomment-4008901865
Can you elaborate what else needs to be done? I see all tests passed
--
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