realtime icon indicating copy to clipboard operation
realtime copied to clipboard

Realtime subscription fails with large id.in(...) filters due to subscription_subscription_id_entity_filters_key btree size limit (ERROR 54000)

Open ryanengland opened this issue 10 months ago • 2 comments

Bug report

  • [ x ] I confirm this is a bug with Supabase, not with my own application.
  • [ x ] I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

When subscribing to Postgres changes with a large id.in.(...) filter list, Supabase Realtime fails to register the subscription. The server returns ERROR 54000 (program_limit_exceeded) because the subscription table index row size exceeds the btree limit for subscription_subscription_id_entity_filters_key. This prevents realtime updates from being delivered.

To Reproduce

  1. Create a Realtime channel and register a postgres_changes subscription with a filter containing a large list of IDs (e.g., id=in.(<60+ UUIDs>)).
  2. Subscribe to the channel.
  3. Observe the server error in the realtime logs.

Example supabase-js:

const channel = supabase.channel('db-changes');

channel.on(
  'postgres_changes',
  {
    event: '*',
    schema: 'public',
    table: 'destinations',
    filter: `id=in.(${hugeListOfUuids.join(',')})`,
  },
  payload => {
    console.log(payload);
  }
);

channel.subscribe();

Observed from Supabase:

receive error realtime:db-changes system {
  "channel": "db-changes",
  "extension": "postgres_changes",
  "message": "Unable to subscribe to changes with given parameters. An exception happened so please check your connect parameters: [schema: public, table: destinations, filters: [{\"id\", \"in\", \"{...}\"}]]. Exception: ERROR 54000 (program_limit_exceeded) index row size 3056 exceeds btree version 4 maximum 2704 for index \"subscription_subscription_id_entity_filters_key\" ...",
   "table": subscription
   "constraint": subscription_subscription_id_entity_filters_key
    "hint": Values larger than 1/3 of a buffer page cannot be indexed.
Consider a function index of an MD5 hash of the value, or use full text indexing.

Index row references tuple (7,3) in relation \"subscription\".", "status": "error"}
}

Expected behavior

According to the documentation this filter is only limited to 100 values, but if there is also a size limit, this should also be documented. This error can only be surfaced by enabling realtime debug logs in the Supabase constructor.

Ideally, Supabase should either this this to accept the subscription regardless of filter size (perhaps using the MD5 fix documented in the returned error), or return a clearer error / limit guidance before attempting to insert the oversized filter into the subscription table (e.g., reject with a user‑facing limit or documented max size).

System information

  • Version of supabase-js: [e.g. 6.0.2]
  • Running against Supabase Cloud (Hosted)

Additional context

This is a React Native app. We dynamically subscribe to a growing set of destination IDs. Once the filter list grows large, realtime registration fails with the error above and no updates are delivered. If there’s a documented max filter size or a recommended workaround (e.g., server-side views, channel per subset, etc.), that would be helpful.

This can currently be worked around by batching the IDs so that they don't get near the limit (10-20 per batch)

ryanengland avatar Jan 14 '26 17:01 ryanengland

Reproduced this locally and found the exact ceiling, which turns out to be lower than anything documented.

The unique index on realtime.subscription covers filters by value, so the whole filter array has to fit btree's 2704-byte tuple limit. Inserting id=in.(...) subscriptions with a growing number of uuids on supabase/postgres:17.6.1.127:

largest in-list that inserts: 69 uuids
first failure at 70 uuids: 54000 index row size 2712 exceeds btree version 4
  maximum 2704 for index "subscription_subscription_id_entity_filters_action_filter_selec"

So the practical maximum is 69 uuids, while realtime.subscription_check_filters raises too many values for 'in' filter. Maximum 100 — the limit the code itself enforces, and the one the docs describe, can never be reached for a uuid column. It also depends on value length rather than count, so the same filter list is fine on an int column and fails on a uuid one, which is why this shows up as an arbitrary-looking limit.

The fix I've put up indexes sha256(filters::text) instead of the array itself, and points the upsert's conflict target at the same expression. Uniqueness is unchanged, the size ceiling disappears, and the 100-value guard becomes reachable — after the change the loop above stops at exactly 100 with the trigger's own error rather than 54000.

One thing worth flagging separately, since it is not obvious from the issue: Realtime.Tenants.Migrations provisions a brand-new tenant from priv/repo/tenant_db_dump_<major>.sql and then records every migration as applied without replaying any of them, so a schema change like this has to ship with regenerated dumps or new tenants silently keep the old index. The workflow that regenerates them is gated to same-repo PRs (if: github.event.pull_request.head.repo.full_name == github.repository), so I updated the three snapshot files by hand and verified a fresh database loaded from the edited dump accepts a 100-value filter through the real upsert statement.

hamodywe avatar Aug 15 '26 00:08 hamodywe

:tada: This issue has been resolved in version 2.148.5 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

realtime-release-bot avatar Oct 27 '26 19:10 realtime-release-bot