[PATCH] Add hint for misspelled relations

From: Steve Chavez <steve(at)supabase(dot)io>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: [PATCH] Add hint for misspelled relations
Date: 2025-12-02 02:46:18
Message-ID: CAGRrpzaBQdPdSRXwHnLnCvs=f1a1abcecgBq5f5s+XPGU7f_zQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello hackers,

Currently misspelled columns offer a hint but not misspelled relations.

This patch enables that, the result is like:

-- having this table
create table clients (id int);
-- we misspell the table name
select * from cliants;
ERROR: relation "cliants" does not exist
LINE 1: select * from cliants;
HINT: Perhaps you meant to reference the table "public.clients".

The possible matches are searched in pg_class for the schemas present in
search_path (or if the relation is qualified, it only searches matches in
that schema). The logic reuses the `varstr_levenshtein_less_equal` function
similar to how the column matching is done.

If there's a tie in the fuzzy match, it's solved by preferring the schema
that appears first on the search path. If that fails, then the
lexicographic order is used to break the tie.

One problem is that scanning all pg_class entries can get expensive on big
catalogs, so the number of searches is capped by MAX_REL_HINT_CANDIDATES.
I've set this to 4096 arbitrarily, any guidance on what would be a good
number is appreciated. Personally I've seen a catalog that contains 125K
tables, with mostly auto generated names. For these cases I don't think the
hint helps that much anyway, so it seemed fine to bail here.

The changes are split into two commits, one refactoring some reusable
functions for easier review and another one implementing the relation hint.

Any feedback is welcomed.

Best regards,
Steve Chavez

[1]:

Attachment Content-Type Size
0001-refactor-isolate-relation-errors-to-a-function.patch text/x-patch 4.4 KB
0002-add-a-hint-for-a-missing-relation.patch text/x-patch 13.4 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2025-12-02 02:46:56 Re: [Patch] Windows relation extension failure at 2GB and 4GB
Previous Message Sutou Kouhei 2025-12-02 02:39:57 Re: Make COPY format extendable: Extract COPY TO format implementations