Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL Slow query: count articles, group by category, any way to optimize?
    primarykey
    data
    text
    <p>Is there any way to optimize this query? It takes more than 2.5 secs.</p> <pre><code>SELECT articles.categories_id, COUNT(articles.id) AS count FROM articles WHERE articles.created &gt;= DATE_SUB(NOW(), INTERVAL 48 HOUR) GROUP BY articles.categories_id ORDER BY count DESC CREATE TABLE IF NOT EXISTS `articles` ( `id` int(11) NOT NULL, `categories_id` int(11) NOT NULL, `feeds_id` int(11) NOT NULL DEFAULT '0', `users_id` int(11) NOT NULL DEFAULT '1', `title` varchar(255) CHARACTER SET utf8 NOT NULL, `sefriendly` varchar(255) CHARACTER SET utf8 NOT NULL, `body` text CHARACTER SET utf8, `source` varchar(255) CHARACTER SET utf8 DEFAULT NULL, `created` datetime NOT NULL, `edited` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `fingerprint` varchar(32) CHARACTER SET utf8 NOT NULL, `type` int(1) NOT NULL DEFAULT '1' COMMENT '1 =&gt; Feed fetched article\n2 =&gt; User submitted article', `description` varchar(255) CHARACTER SET utf8 DEFAULT NULL, `keywords` text CHARACTER SET utf8, `status` int(1) NOT NULL DEFAULT '0' COMMENT '0 =&gt; Passive\n1 =&gt; Active\n2 =&gt; Pending', PRIMARY KEY (`id`), KEY `categories_id` (`categories_id`) USING BTREE, KEY `feeds_id` (`feeds_id`) USING BTREE, KEY `users_id` (`users_id`) USING BTREE, KEY `fingerprint` (`fingerprint`) USING BTREE, KEY `title` (`title`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci ROW_FORMAT=COMPACT; </code></pre> <p>I already use caching, so there is no problem in terms of code. </p> <p>This is the explain sql result:</p> <pre><code>id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE articles index NULL categories_id 4 NULL 120411 Using where; Using temporary; Using file sort </code></pre> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload