From 2efd1fd4bac0691301fef679cffc91bf20f2e61b Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Mon, 19 Aug 2024 06:44:55 +0100 Subject: [PATCH] Add indexes on sizes.size Pretty fast to query (~70ms), but in total execution time it's the most expensive query because it's called so often. This makes it go down to ~0.5ms. --- db/migrate/2024-08-19-1-rm-updates2.sql | 1 + db/migrate/2024-08-19-1-sizes-idx.sql | 1 + db/schema.gotxt | 15 ++++----------- 3 files changed, 6 insertions(+), 11 deletions(-) create mode 100644 db/migrate/2024-08-19-1-rm-updates2.sql create mode 100644 db/migrate/2024-08-19-1-sizes-idx.sql diff --git a/db/migrate/2024-08-19-1-rm-updates2.sql b/db/migrate/2024-08-19-1-rm-updates2.sql new file mode 100644 index 00000000..10a48fc4 --- /dev/null +++ b/db/migrate/2024-08-19-1-rm-updates2.sql @@ -0,0 +1 @@ +drop table updates; diff --git a/db/migrate/2024-08-19-1-sizes-idx.sql b/db/migrate/2024-08-19-1-sizes-idx.sql new file mode 100644 index 00000000..8c7b7246 --- /dev/null +++ b/db/migrate/2024-08-19-1-sizes-idx.sql @@ -0,0 +1 @@ +create index "sizes#size" on sizes(size); diff --git a/db/schema.gotxt b/db/schema.gotxt index bd1d6314..79b9bf86 100644 --- a/db/schema.gotxt +++ b/db/schema.gotxt @@ -141,6 +141,7 @@ create table sizes ( {{sqlite `width || ',' || height || ',' || scale`}} ) stored ); +create index "sizes#size" on sizes(size); insert into sizes (width, height, scale) values (0, 0, 0); create table hit_counts ( @@ -268,16 +269,6 @@ create index "campaign_stats#site_id#day" on campaign_stats(site_id, day desc); {{cluster "campaign_stats" "campaign_stats#site_id#day"}} {{replica "campaign_stats" "campaign_stats#site_id#path_id#campaign_id#ref#day"}} -create table updates ( - id {{auto_increment}}, - subject varchar not null, - body varchar not null, - - created_at timestamp not null {{check_timestamp "created_at"}}, - show_at timestamp not null {{check_timestamp "show_at"}} -); -create index "updates#show_at" on updates(show_at); - create table exports ( export_id {{auto_increment}}, site_id integer not null, @@ -362,6 +353,8 @@ insert into version values ('2022-11-17-1-open-at'), ('2023-05-16-1-hits'), -- 2.6 - ('2023-12-15-1-rm-updates'); + ('2023-12-15-1-rm-updates'), + ('2024-08-19-1-sizes-idx'), + ('2024-08-19-2-rm-updates2'); -- vim:ft=sql:tw=0