File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
5626type Option func (* Catalog ) error
Original file line number Diff line number Diff line change @@ -15,20 +15,10 @@ func (c *Catalog) CreateNamespace(name string) (int64, error) {
1515
1616func (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
3424type NamespaceInfo struct {
Original file line number Diff line number Diff line change 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.
2218package seed
2319
2420import (
@@ -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
204194func loadSettings (fsys fs.FS ) (Settings , error ) {
You can’t perform that action at this time.
0 commit comments