Skip to content

perf(jdbc): add key_subscriptions(subscription_id) index for ApiKey appender warmup (APIM-14263)#17323

Open
wbabyte wants to merge 1 commit into
4.11.xfrom
wbabyte/APIM-14262-key-subscriptions-index
Open

perf(jdbc): add key_subscriptions(subscription_id) index for ApiKey appender warmup (APIM-14263)#17323
wbabyte wants to merge 1 commit into
4.11.xfrom
wbabyte/APIM-14262-key-subscriptions-index

Conversation

@wbabyte
Copy link
Copy Markdown
Contributor

@wbabyte wbabyte commented Jun 1, 2026

Fixes APIM-14263.

What

Adds a JDBC index key_subscriptions(subscription_id) (Liquibase v4_11_8/05_…; additive — keeps the existing PK).

Why

The gateway-sync ApiKey appender (APIM-14203) loads keys via
select … from keys where id in (select key_id from key_subscriptions where subscription_id in (…chunk…)).
key_subscriptions's only index is the PK (key_id, subscription_id) — leading column key_id — so where subscription_id in (…) cannot use it and Postgres does a Parallel Seq Scan per chunk.

At ~2.4M subs / ~800k key_subscriptions rows this is ~2.3 s/chunk (EXPLAIN ANALYZE); over thousands of chunks the real-gateway warmup hung >30 min with 0/8109 APIs deployed. The same dataset with no api-keys warms up in ~80 s.

Mongo parity

MongoDB already has the equivalent — keys.{subscriptions:1} (KeysSubscriptionsIndexUpgrader, name s1). This PR closes the JDBC↔Mongo parity gap; no Mongo change needed.

Notes

  • Additive only; no index dropped.
  • Independent of (and complementary to) the subscriptions (plan,id) index (APIM-14087) already on 4.11.x.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@wbabyte wbabyte self-assigned this Jun 1, 2026
@wbabyte wbabyte changed the title perf(jdbc): add key_subscriptions(subscription_id) index for ApiKey appender warmup (APIM-14262) perf(jdbc): add key_subscriptions(subscription_id) index for ApiKey appender warmup (APIM-14263) Jun 1, 2026
@wbabyte wbabyte force-pushed the wbabyte/APIM-14262-key-subscriptions-index branch from 1f2c7af to 20bc6ea Compare June 1, 2026 22:10
@wbabyte wbabyte marked this pull request as ready for review June 1, 2026 22:12
@wbabyte wbabyte requested a review from a team as a code owner June 1, 2026 22:12
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 1, 2026

@aditya-goyal01 aditya-goyal01 added the apply-on-4-12-x Mergify: apply on 4.12.x label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

apply-on-4-12-x Mergify: apply on 4.12.x apply-on-master

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants