ゆれ?
6.9秒も動いているらしい。
SELECT SUM("account_stats"."statuses_count") FROM "accounts" INNER JOIN "account_stats" ON "account_stats"."account_id" = "accounts"."id" WHERE "accounts"."domain" IS NULL
Explainの結果
Aggregate (cost=37791.30..37791.31 rows=1 width=32)
-> Nested Loop (cost=0.42..37791.30 rows=1 width=8)
-> Seq Scan on accounts (cost=0.00..37788.66 rows=1 width=8)
Filter: (domain IS NULL)
-> Index Scan using index_account_stats_on_account_id on account_stats (cost=0.42..2.64 rows=1 width=16)
Index Cond: (account_id = accounts.id)
bingチャットの回答
Seq Scan on accountsという行は、accountsテーブルの全ての行をスキャンしていることを示しています。これは、accountsテーブルにdomain列にインデックスが貼られていないことを意味します。
Index Scan using index_account_stats_on_account_id on account_statsという行は、account_statsテーブルの全ての行をインデックススキャンしていることを示しています。これは、account_statsテーブルにaccount_id列にインデックスが貼られていることを意味します。
Aggregateという行は、account_statsテーブルからstatuses_count列の値を集計していることを示しています。これは、account_statsテーブルにstatuses_count列にインデックスが貼られていないことを意味します。
これらの問題を解決するためには、accountsテーブルにdomain列にインデックスを貼る、account_statsテーブルにstatuses_count列にインデックスを貼るなどの方法があります。
情弱なのでarrows Nをいつでもカエドキプログラムで白ロム購入しました。
初回全話無料のマンガアプリ「少年ジャンプ+」で「[43話]タヌキツネのゴン」を読んでます! #ジャンププラス https://shonenjumpplus.com/red/content/ec1061999
初回全話無料のマンガアプリ「少年ジャンプ+」で「[第34話]幼稚園WARS」を読んでます! #ジャンププラス https://shonenjumpplus.com/red/content/ec1061994