-
Notifications
You must be signed in to change notification settings - Fork 19
WIP Set max character count for byName index in subgraph_domains table
#1815
Changes from all commits
9cbc064
b666142
32f78e0
cf8a6f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@ensnode/ensdb-sdk": patch | ||
| --- | ||
|
|
||
| Updated the max character count (length constraint) for the `byName` partial index defined on the `subgraph_domains` table in the "abstract" ENSIndexer Schema. |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||||||||
| import { index, onchainTable, relations } from "ponder"; | ||||||||||||||
| import { index, onchainTable, relations, sql } from "ponder"; | ||||||||||||||
| import type { Address } from "viem"; | ||||||||||||||
|
|
||||||||||||||
| import { monkeypatchCollate } from "../lib/collate"; | ||||||||||||||
|
|
@@ -93,7 +93,23 @@ export const subgraph_domain = onchainTable( | |||||||||||||
| expiryDate: t.bigint(), | ||||||||||||||
| }), | ||||||||||||||
| (t) => ({ | ||||||||||||||
| byName: index().on(t.name), | ||||||||||||||
| /** | ||||||||||||||
| * Maximum character length for the `subgraph_domain.name` partial index. | ||||||||||||||
| * | ||||||||||||||
| * PostgreSQL B-tree indexes have a maximum size of 8,191 bytes (8KB) per entry. | ||||||||||||||
| * Without a limit, index creation fails for entries exceeding this size. | ||||||||||||||
| * For example, spam domain records with thousands of characters in `name` column | ||||||||||||||
| * cause index creation to fail. | ||||||||||||||
| * | ||||||||||||||
| * UTF-8 uses 1-4 bytes per character. For the safe maximum of 4 bytes: | ||||||||||||||
| * 8,191 ÷ 4 = ~2,000 characters would be the upper bound. | ||||||||||||||
| * | ||||||||||||||
| * We use 255, which is sufficient for virtually all ENS names in practice. | ||||||||||||||
| * This is implemented as a partial index with WHERE length(name) <= 255, | ||||||||||||||
| * which excludes oversized spam entries while still allowing normal lookups | ||||||||||||||
| * (e.g. where: { name: "foo.eth" }) to use the index. | ||||||||||||||
|
Comment on lines
+109
to
+110
|
||||||||||||||
| * which excludes oversized spam entries while still allowing normal lookups | |
| * (e.g. where: { name: "foo.eth" }) to use the index. | |
| * which excludes oversized spam entries while still indexing typical-length names. | |
| * Note: PostgreSQL can only use this partial index when a query's WHERE clause | |
| * implies the predicate (e.g. includes a matching length constraint), so simple | |
| * equality filters alone (name = $1) may not always qualify for index usage. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment refers to
subgraph_domain.name, but the actual table name issubgraph_domains(and this index is created on that table). Consider updating the wording to referencesubgraph_domains.nameto avoid confusion when debugging in Postgres.