Skip to content

Commit acf9be6

Browse files
committed
DuckDB rewrite: add unique indexes for primary keys
1 parent 2a2769b commit acf9be6

File tree

8 files changed

+23
-0
lines changed

8 files changed

+23
-0
lines changed

lib/agency.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ FROM read_csv(
3131
-- We omit DATE/TIME/TIMESTAMP because GTFS formats them differently.
3232
auto_type_candidates = ['NULL', 'BIGINT', 'DOUBLE', 'VARCHAR']
3333
);
34+
35+
-- For a primary key, DuckDB doesn't create an index automatically.
36+
CREATE UNIQUE INDEX agency_agency_id ON agency(agency_id);
3437
`)
3538

3639
workingState.nrOfRowsByName.set('agency', await queryNumberOfRows(db, 'agency', opt))

lib/levels.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ FROM read_csv(
3030
}
3131
);
3232
33+
-- For a primary key, DuckDB doesn't create an index automatically.
34+
CREATE UNIQUE INDEX levels_level_id ON levels(level_id);
3335
`)
3436

3537
workingState.nrOfRowsByName.set('levels', await queryNumberOfRows(db, 'levels', opt))

lib/pathways.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ FROM read_csv(
8383
${has_reversed_signposted_as ? `, reversed_signposted_as: 'TEXT'` : ``}
8484
}
8585
);
86+
87+
-- For a primary key, DuckDB doesn't create an index automatically.
88+
CREATE UNIQUE INDEX pathways_pathway_id ON pathways(pathway_id);
8689
`)
8790

8891
workingState.nrOfRowsByName.set('pathways', await queryNumberOfRows(db, 'pathways', opt))

lib/routes.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@ FROM read_csv(
311311
}
312312
);
313313
314+
-- For a primary key, DuckDB doesn't create an index automatically.
315+
CREATE UNIQUE INDEX routes_route_id ON routes(route_id);
316+
314317
CREATE INDEX routes_route_short_name ON routes (route_short_name);
315318
`)
316319

lib/shapes.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ FROM (
6666
ORDER BY shape_id, shape_pt_sequence
6767
) t
6868
GROUP BY shape_id;
69+
70+
-- For a primary key, DuckDB doesn't create an index automatically.
71+
CREATE UNIQUE INDEX shapes_shape_id ON shapes(shape_id);
6972
`)
7073

7174
// Note: This is not the number of shapes.txt rows!

lib/stop_times.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ FROM read_csv(
9090
}
9191
);
9292
93+
-- For a primary key, DuckDB doesn't create an index automatically.
94+
CREATE UNIQUE INDEX stop_times_trip_id_stop_sequence ON stop_times(trip_id, stop_sequence);
95+
9396
-- todo: are all of them beneficial/necessary?
9497
CREATE INDEX stop_times_trip_id ON stop_times (trip_id);
9598
CREATE INDEX stop_times_stop_id ON stop_times (stop_id);

lib/stops.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ ORDER BY root_id, recursion_level, stop_id;
179179
-- ADD CONSTRAINT stops_parent_station_fkey
180180
-- FOREIGN KEY (parent_station) REFERENCES stops;
181181
182+
-- For a primary key, DuckDB doesn't create an index automatically.
183+
CREATE UNIQUE INDEX stops_stop_id ON stops(stop_id);
184+
182185
CREATE INDEX stops_parent_station ON stops (parent_station);
183186
${opt.stopsLocationIndex ? `CREATE INDEX stops_stop_loc ON stops (stop_loc);` : ''}
184187
`)

lib/trips.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ FROM read_csv(
8282
${has_bikes_allowed ? `bikes_allowed: 'INTEGER',` : ``}
8383
}
8484
);
85+
86+
-- For a primary key, DuckDB doesn't create an index automatically.
87+
CREATE UNIQUE INDEX trips_trip_id ON trips(trip_id);
8588
`)
8689

8790
workingState.nrOfRowsByName.set('trips', await queryNumberOfRows(db, 'trips', opt))

0 commit comments

Comments
 (0)