Code: Select all
create table account_transactions
(
id int auto_increment primary key,
account_id int not null,
amount decimal(10, 2) not null,
type varchar(255) not null,
created_at datetime not null,
updated_at datetime not null,
constraint FK_does_not_matter
foreign key (account_id) references accounts (id),
index account_transactions_created_at (created_at),
-- + some other irrelevant columns and indexes
)
collate = utf8mb4_unicode_ci;
create table accounts
(
id int auto_increment primary key,
project_id int not null,
user_id int not null,
constraint FK_does_not_matter
foreign key (user_id) references users (id),
constraint FK_does_not_matter
foreign key (project_id) references projects (id),
-- + some other irrelevant columns and indexes
)
collate = utf8mb4_unicode_ci;
Code: Select all
account_transactionsDie Code: Select all
SELECT SUM(c0_.amount) AS sclr_0
FROM account_transactions c0_
LEFT JOIN accounts c1_ ON c0_.account_id = c1_.id
WHERE c0_.created_at >= ? -- currently '2025-12-04 00:00:00'
AND c1_.project_id = ?;
Der Abfrageplan sieht für mich in Ordnung aus:
Code: Select all
id,select_type,table,type,possible_keys,key,key_len,ref,rows,Extra
1,SIMPLE,c1_,ref,"PRIMARY,IDX_does_not_matter",IDX_does_not_matter,4,const,270,Using index
1,SIMPLE,c0_,ref,"IDX_does_not_matter,account_transactions_created_at",IDX_does_not_matter,4,dbname.c1_.id,257,Using where
Das alles läuft auf der AWS RDS db.t3.medium-Instanz, Engine-Version 10.11.13 (MariaDB), und ich verbinde mich über EC2 damit Beispiel.
Diese glanzlose Leistung bereitet mir eine Menge Probleme, und ich verstehe wirklich nicht, wo das Problem liegt. Ist es AWS RDS? Liegt es irgendwie am Netzwerk, obwohl sie sich angeblich im selben AWS-Netzwerk befinden? Ich glaube nicht, dass mir irgendwelche Indizes fehlen, es gibt hier wirklich nichts mehr zu indizieren.
P.S. Ich habe keine Ahnung, warum im Abfrageplan „rows=270/257“ steht. Wenn Sie alle Zeilen auswählen, werden 859 Zeilen für die betreffende Projekt-ID angezeigt (aber eigentlich besteht das Problem mehr oder weniger für alle Projekte).
Mobile version