perf: index telemetry timestamps

Index timestamp lookups used by telemetry statistics and result listing.
This commit is contained in:
Josef Schlehofer 2026-08-10 08:45:42 +02:00
parent e8dcccf1a8
commit 722689727b
No known key found for this signature in database
GPG key ID: 942FF3271E2AC7DB
4 changed files with 19 additions and 1 deletions

View file

@ -138,6 +138,10 @@ function getPdo($returnErrorMessage = false)
`log` longtext
);
');
// Every query that is not a lookup by id orders or filters by
// timestamp, and without this the table is scanned in full each
// time. The other schemas declare the same index.
$pdo->exec('CREATE INDEX IF NOT EXISTS `speedtest_users_timestamp` ON `speedtest_users` (`timestamp`);');
return $pdo;
}

View file

@ -33,4 +33,10 @@ GO
ALTER TABLE [dbo].[speedtest_users] ADD CONSTRAINT [DF_speedtest_users_timestamp] DEFAULT (getdate()) FOR [timestamp]
GO
CREATE NONCLUSTERED INDEX [speedtest_users_timestamp] ON [dbo].[speedtest_users]
(
[timestamp] ASC
) ON [PRIMARY]
GO

View file

@ -42,7 +42,8 @@ CREATE TABLE `speedtest_users` (
-- Indexes for table `speedtest_users`
--
ALTER TABLE `speedtest_users`
ADD PRIMARY KEY (`id`);
ADD PRIMARY KEY (`id`),
ADD KEY `speedtest_users_timestamp` (`timestamp`);
--
-- AUTO_INCREMENT for dumped tables

View file

@ -107,6 +107,13 @@ ALTER TABLE ONLY speedtest_users
ADD CONSTRAINT speedtest_users_pkey PRIMARY KEY (id);
--
-- Name: speedtest_users_timestamp; Type: INDEX; Schema: public; Owner: speedtest
--
CREATE INDEX speedtest_users_timestamp ON speedtest_users USING btree ("timestamp");
--
-- PostgreSQL database dump complete
--