6 Commits
Author SHA1 Message Date
Joshen Lim 53ffdf75c9 Joshenlim/fe 4945 cmd k support searching for all table (#53262)
## Context

Probably the final piece for this series of changes towards resource
aware Cmd K. We currently only present results for tables when searching
in Cmd K, this PR adds in other entity types like views, materialized
views, foreign tables, and partitioned tables (only the parent)

Note that the results excludes entities created from database extensions
to reduce the chance of noise

<img width="500" alt="image"
src="https://github.com/user-attachments/assets/27bf5026-937a-4883-b365-75694d551a39"
/>

## Related changes
- Tweaked the entity icon for partitioned tables a little to be blue
(previously gray) and
- Added an entity icon for child partition tables in the table editor
that's slightly lighter than the partition table icon, currently child
partition tables just render with the same icon as tables which can be
confusing
<img width="286" height="128" alt="image"
src="https://github.com/user-attachments/assets/638af7c3-512d-4264-bfae-0a8827b3ef94"
/>
- Note that i'm planning to look into this separately RE how to better
render child partition tables so this might go away subsequently

## Performance

As always, ran a claude benchmarking session - this runs on debounced
keystrokes against a live catalog, so it's benchmarked at scale:
**45,653 `pg_class` rows**
- 12k tables
- 3,143 views
- 3,002 matviews
- 3,001 foreign tables)
Taking a median of 15 runs, all variants measured against the same
catalog in one process.

| scenario | query | master | this PR | worst |
|---|---|---|---|---|
| exact table name | `t_500` | 19.5ms | 24.3ms | 29.1ms |
| view name | `v_10` | 19.3ms | 23.7ms | 25.8ms |
| foreign table name | `ft_10` | 18.9ms | 24.1ms | 26.9ms |
| no match | `zzz_nothing` | 19.4ms | 24.0ms | 27.5ms |
| broad prefix (~3k matches) | `t_1` | 30.8ms | 38.7ms | 45.1ms |
| broad matview prefix | `mv_1` | 26.6ms | 37.5ms | 41.7ms |
2026-11-12 11:37:45 +08:00
Joshen Lim 06d43f6881 Joshenlim/fe 4721 cmd k support searching for triggers (#52755)
## Context

Building off from
[here](https://github.com/supabase/supabase/pull/52751) to make Cmd+K
resource-aware so finding and inspecting anything in a project doesn't
depend on knowing where it lives in the dashboard.

Specifically looking into database entities for now - end state would be
that you could search for a table name for example, and Cmd K will pull
up everything related to that table for you to skim (e.g Policies,
Functions, Triggers, etc). Changes in this PR sets up searching for
**database triggers**, and will probably be the last database entity
that we'll add into context aware cmd K for now given that we'll have
tables, policies, functions and triggers which are the primary building
blocks for a project.

<img width="500" alt="image"
src="https://github.com/user-attachments/assets/242ec517-88cd-4f3d-96ce-741edaa8560d"
/>

Triggers will also match if it's function matches the search input, and
its description will tweak slightly as well
<img width="500" alt="image"
src="https://github.com/user-attachments/assets/65f515df-b875-4b92-95b7-00389d8a070b"
/>

## Performance

Had Claude do some benchmarking against `getSearchEntitiesSql` (`EXPLAIN
ANALYZE`, median of 5 runs, local Postgres, warm cache) on one synthetic
catalog:
- 12,000 tables (36,651 `pg_class`), 6,001 policies, 27,261 `pg_proc`
(12,000 user + 12,000 extension-owned functions), 56,304 `pg_trigger`
- 3,500 user triggers, 500 of which run one shared function; the rest
are internal FK triggers
  - 297,921 `pg_depend`.

Compared against master (tables + policies) and the functions PR (before
triggers).

| Search | What it exercises | master | functions PR | this PR | Δ this
PR |
|---|---|---|---|---|---|
| `t_1` | broad table match | 12ms | 26ms | 30ms | +4ms |
| `p_1` | broad policy-name match | 15ms | 27ms | 35ms | +8ms |
| `fn_1` | broad function match | 10ms | 26ms | 33ms | +7ms |
| `trg_1` | broad trigger-name match | 9ms | 23ms | 32ms | +9ms |
| `trg_` | every user trigger matches by name | 10ms | 25ms | 40ms |
+15ms |
| `audit_row_fn` | function match; its 500 triggers match only through
the function | 9ms | 24ms | 31ms | +7ms |
| `ri_constraint` | only internal FK triggers match | 9ms | 24ms | 30ms
| +6ms |
| `stress.fn_1` | schema-qualified | 12ms | 33ms | 40ms | +7ms |
| `zzz` | no match | 9ms | 22ms | 27ms | +5ms |

- Triggers add +4 to +15ms over the functions PR. The worst case is a
search matching every user trigger, at 40ms in total.
- Matching triggers through their function shares the single
`pg_trigger` pass the name search already does, with no extra scan. A
separate pass measured about 30ms more on every search.

## To test
- [ ] Search a table name: Tables first, then policies, and functions,
and triggers
- [ ] Search a trigger name: it appears under triggers and opens the
editor panel in database/triggers
- [ ] Search a function name: trigger results should appear if the
trigger uses that function
- [ ] Trigger outside public: schema filter switches and the trigger
opens
2026-11-06 17:04:39 +08:00
Joshen Lim ebe8849f8b Skip resource aware search in cmd k while in a sub page (#52773)
## Context

Related to the resource aware CMD K changes, this just skips the request
for the resource aware search when searching in the CMD K field input if
the user is on any sub page, as the search will no longer be relevant.
2026-11-05 13:03:34 +08:00
Joshen Lim 5152899fac Joshenlim/fe 4720 cmd k support searching for functions (#52751)
## Context

Building off from
[here](https://github.com/supabase/supabase/pull/52678) to make Cmd+K
resource-aware so finding and inspecting anything in a project doesn't
depend on knowing where it lives in the dashboard.

Specifically looking into database entities for now - end state would be
that you could search for a table name for example, and Cmd K will pull
up everything related to that table for you to skim (e.g Policies,
Functions, Triggers, etc). Changes in this PR sets up searching for
**database functions**.

<img width="607" height="531" alt="image"
src="https://github.com/user-attachments/assets/b4a2cd15-9874-4e80-80d4-d343d8c70fc3"
/>

## Performance

Ran a Claude session to benchmark `getSearchEntitiesSql` against the
version on master (tables and policies only), on the same synthetic
catalog:
- 12,000 tables (36,651 `pg_class`), 6,001 policies, 27,258 `pg_proc`
(12,000 user + 12,000 extension-owned functions), 290,915 `pg_depend`.
- Median of 5 runs, `EXPLAIN ANALYZE`, local Postgres (warm cache).

| Search | Matches | master | this PR |
|---|---|---|---|
| `t_1` | ~1/9 of tables | 12ms | 23ms |
| `p_1` | broad policy-name match | 13ms | 25ms |
| `fn_1` | user + extension functions | 8ms | 23ms |
| `fn_` | every function | 8ms | 29ms |
| `stress.fn_1` | schema-qualified | 10ms | 30ms |
| `zzz` | nothing | 9ms | 22ms |

- Adding functions costs +11 to +21ms at this scale
- Most of it is fixed (+13ms even for a query that matches nothing): one
pass over `pg_proc`, plus building the set of extension-owned functions.
It doesn't grow with the number of matches.

## To test
- [ ] Search a table name: Tables first, then policies, and functions
- [ ] Search a function name: it appears under Functions and opens the
editor panel in database/functions
- [ ] Function outside public: schema filter switches and the function
opens
2026-11-05 13:02:44 +08:00
Joshen Lim 2b55f7db9a Joshenlim/fe 4719 cmd k support searching for policies (#52678)
## Context

Continue to build off from
[here](https://github.com/supabase/supabase/pull/52205) to make Cmd+K
resource-aware so finding and inspecting anything in a project doesn't
depend on knowing where it lives in the dashboard.

Specifically looking into database entities for now - end state would be
that you could search for a table name for example, and Cmd K will pull
up everything related to that table for you to skim (e.g Policies,
Functions, Triggers, etc). Changes in this PR sets up searching for RLS
policies.

<img width="609" height="525" alt="image"
src="https://github.com/user-attachments/assets/212a430a-314d-48c4-a27c-2f9bb06e8457"
/>

Policies are matched on, in priority, its name and the target table.

## Performance checking

Just ran a check with Claude just to make sure that the added SQL
doesn't cause any performance degradation on the database. Plan guard
passes at 12,000 tables, under its 500ms budget. Also benchmarked
locally with a 3-character query matching every policy, results look
good so should be alright:

| Catalog | Worst-case search | No-match baseline |
|---|---|---|
| 36k policies | ~52–64ms | ~16ms |
| 120k policies | ~118–134ms | ~63ms |

## To test

- [x] Search a table name: Tables first, then its policies, under
Policies
- [x] Search a policy name: it appears under Policies and opens the
editor panel in database/policies
- [x] Policy outside `public`: schema filter switches and the policy
opens
2026-11-04 14:26:37 +08:00
Joshen Lim 7d63d764fc Joshenlim/fe 4712 cmd k support searching for database tables (#52205)
## Context

Looking into some kaizen improvements for Cmd+K, with the overarching
idea to make Cmd+K resource-aware so finding and inspecting anything in
a project doesn't depend on knowing where it lives in the dashboard.

Specifically looking into database entities for now - end state would be
that you could search for a table name for example, and Cmd K will pull
up everything *related* to that table for you to skim (e.g Policies,
Functions, Triggers, etc). Changes in this PR sets the foundation here
by starting with just the tables.
<img width="500" alt="image"
src="https://github.com/user-attachments/assets/65054781-2385-416c-aed9-f142380e4454"
/>

This might be similar to how we currently support searching for database
entities via these "Queries" section, but these only search within the
context of the entity category, not across (e.g only tables, only
policies)
<img width="500" alt="image"
src="https://github.com/user-attachments/assets/66ca16c6-9551-4134-b1e1-0b0c4b004085"
/>

The idea isn't to replace this, but provide another way to find your
database entities so that
- You can see related entities to what you're searching at a glance
- You don't need to go to a 2nd level nav in Cmd K 

Also fwiw the bulk of the LOC changes in here are mainly tests actually,
actual LOC changes are +385, -22
2026-10-23 23:24:56 +08:00