Skip to content

Commit 76901be

Browse files
committed
Revert "core/seed: load a dialect's relations on demand"
Relations are seeded with the rest of the dialect again, so every record in a dialect directory is applied as it is read and the catalog has no notion of a seed that runs later. The cost this was avoiding — about 40ms per invocation to install PostgreSQL's system catalogs — comes back, and will be dealt with another way. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011MnoUabwBWW9gaEn2Nj7eG
1 parent 6c188fc commit 76901be

3 files changed

Lines changed: 4 additions & 54 deletions

File tree

internal/core/catalog.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,6 @@ type Catalog struct {
2121
// dialectOID is the dialect this catalog was seeded with. A catalog is
2222
// built for one dialect, so dialect-wide lookups need no other input.
2323
dialectOID int64
24-
25-
// deferred holds the parts of a seed that are only worth loading if a
26-
// query asks for them. They run at most once, when a namespace lookup
27-
// misses.
28-
deferred []func(*Catalog) error
29-
deferredDone bool
30-
}
31-
32-
// SeedLater registers a part of the seed to run the first time the catalog is
33-
// asked for a namespace it does not have. A dialect's system catalogs run to
34-
// thousands of columns that most queries never reference, so loading them is
35-
// left until one does.
36-
func (c *Catalog) SeedLater(fn func(*Catalog) error) {
37-
c.deferred = append(c.deferred, fn)
38-
}
39-
40-
// runDeferred runs the deferred seeds, reporting whether it had any to run.
41-
func (c *Catalog) runDeferred() (bool, error) {
42-
if c.deferredDone || len(c.deferred) == 0 {
43-
return false, nil
44-
}
45-
// Marked done up front: a deferred seed looks namespaces up itself, and
46-
// must not set itself running again.
47-
c.deferredDone = true
48-
for _, fn := range c.deferred {
49-
if err := fn(c); err != nil {
50-
return false, err
51-
}
52-
}
53-
return true, nil
5424
}
5525

5626
type Option func(*Catalog) error

internal/core/namespace.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,10 @@ func (c *Catalog) CreateNamespace(name string) (int64, error) {
1515

1616
func (c *Catalog) NamespaceOID(name string) (int64, error) {
1717
oid, err := c.q.NamespaceOID(context.Background(), name)
18-
if err == nil {
19-
return oid, nil
20-
}
21-
// A namespace the catalog does not have may be one a deferred seed brings
22-
// in — a dialect's system catalogs, which most queries never name and
23-
// which are therefore not loaded until one does.
24-
if ran, derr := c.runDeferred(); derr != nil {
25-
return 0, derr
26-
} else if ran {
27-
if oid, err := c.q.NamespaceOID(context.Background(), name); err == nil {
28-
return oid, nil
29-
}
18+
if err != nil {
19+
return 0, fmt.Errorf("namespace %q: %w", name, err)
3020
}
31-
return 0, fmt.Errorf("namespace %q: %w", name, err)
21+
return oid, nil
3222
}
3323

3424
type NamespaceInfo struct {

internal/core/seed/seed.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
// The lists are JSONL — one record per line — and are applied as they are
1616
// read, so a dialect whose function list runs to thousands of entries is never
1717
// held in memory as a whole. Any of the lists may be left out.
18-
//
19-
// Relations are the exception to "applied as they are read": they are loaded
20-
// the first time a query names a schema the catalog does not yet have, since
21-
// most queries never touch a system catalog.
2218
package seed
2319

2420
import (
@@ -192,13 +188,7 @@ func apply(cat *core.Catalog, fsys fs.FS) error {
192188
if err := stream(fsys, FunctionsFile, b.addFunction); err != nil {
193189
return err
194190
}
195-
196-
// A dialect's system catalogs are thousands of columns that a query only
197-
// occasionally names, so they wait until one does.
198-
cat.SeedLater(func(*core.Catalog) error {
199-
return stream(fsys, RelationsFile, b.addRelation)
200-
})
201-
return nil
191+
return stream(fsys, RelationsFile, b.addRelation)
202192
}
203193

204194
func loadSettings(fsys fs.FS) (Settings, error) {

0 commit comments

Comments
 (0)