Mysql query speed #2232
Replies: 4 comments 8 replies
-
Haven't looked into the database. But yeah, I am self hosting my analytics with Umami. And just recently it's gotten so slow. 7 days of data takes about 10 seconds. 30 days of data takes upwards of a minute, and then I get errors. |
Beta Was this translation helpful? Give feedback.
-
Hello. I'm using MariaDB and saw slow queries too. I recently converted all *_id columns in all tables to "UUID" data type (and NOT varchar 36) and not only saved GB of space, also query speed was good too. So it's possible to get nice speed with mysql and NOT having to switch to PostgreSQL... |
Beta Was this translation helpful? Give feedback.
-
Hey, please do a complete backup of your database before trying this, since I may have overseen something, but my stats are working fine after this change. The change to UUID does not seem to affect queries, since everything is the same when inserting, selecting, etc (uuids as strings, etc). In MariaDB 10.7+ you want to convert all VARCHAR(36) columns (*_id columns) in all tables to the new UUID data type. For example, to change column "user_id" at table "user": Biggest tables are session & website_event so expect some time to reindex / re-struct. I've done it using HeidiSQL (change data type), then you have your ALTER code at tab "Alter code". |
Beta Was this translation helpful? Give feedback.
-
Yeah it will depend on mysql version. With MariaDB everything seems ok from
the version I mentioned
…On Sat, Oct 21, 2023 at 4:37 AM Yaozhi Wang ***@***.***> wrote:
Sorry for the delayed update. I attempted to alter the table yesterday,
but unfortunately discovered that MySQL does not support the UUID column
type. I'm using PlanetScale's database service, which is backed by MySQL. I
inquired on their GitHub
<planetscale/discussion#555>, and it turns
out that this is not feasible with MySQL.
—
Reply to this email directly, view it on GitHub
<#2232 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAI7NGNVBY6OXE2VNIROLD3YAMYOTAVCNFSM6AAAAAA4BEWRA2VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM3TGNBUGQ3TI>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I've used umami for two months, everything works fine until recent two weeks, when my site started to get traffic like 7k - 8k daily views. The query speed became very slow, it often needs larger than 10s to finish, since I deployed it on Vercel, they have a timeout limit of 10s, which causes the website overview page unusable.
My db is deployed on planetscale, so i go to their dashboard and inspect the slowest queries, i got some queries like:
By
explain
the above statement, it showed that mysql only uses the index with onlywebsite_id
column, so i added an index to include all columns involved in the statement:And then the query time dropped down to less than 1s.
That is for queries with
select ?? as x
, where the??
is a column insession
table. For the columns inwebsite_event
table, i have to add that column into index:So now, it is usable for time range Today/24 hours. However when i set the time range larger than several days, it becomes slow again. I
explain
the query, found that mysql stops using index when time range is large:Another index I've tried is:
But unfortunately, it only works on
event_name
column, for other columns i added some index, but not used by mysql:I'm not an expert on database, I guess the way i add indexes is probably not right. Can anyone help me out?
Beta Was this translation helpful? Give feedback.
All reactions