Mysql slow query: INNER JOIN + ORDER BY causes filesort
Date : March 29 2020, 07:55 AM
Does that help You would need to denormalize a bit, and copy the posts.created_at field into the post_tags table (I called it post_created_at, you could name it how you want): CREATE TABLE `posts_tags` (
`id` int(11) NOT NULL auto_increment,
`post_id` int(11) default NULL,
`tag_id` int(11) default NULL,
`post_created_at` datetime default NULL,
`created_at` datetime default NULL,
`updated_at` datetime default NULL,
PRIMARY KEY (`id`),
KEY `index_posts_tags_on_post_id_and_tag_id` (`post_id`,`tag_id`)
) ENGINE=InnoDB;
(tag_id, post_created_at)
|
MySQL query optimization. Avoiding temporary & filesort
Tag : mysql , By : Robert M
Date : March 29 2020, 07:55 AM
Does that help You can remove the temp table using a Dependent Subquery: select * from
(
SELECT count(productID) AS commonProducts, s.productId, s.packageID
FROM supply as s
WHERE EXISTS
(
select 1 from supply as innerS
where innerS.productID in (2,3,4,5,6,7,8,9,10)
and s.productId = innerS.productId
)
GROUP BY s.packageID
) AS t
ORDER BY t.commonProducts
DESC LIMIT 10
|
Brain-Dead MySQL Select Optimization (Using Temporary, Using Filesort)
Date : March 29 2020, 07:55 AM
it fixes the issue I'm currently working on a project involving Patents pulled the USPTO website, as part of this project I'm using the database created by people from the University of Illinois , Your query is in the form: SELECT some_fields
FROM (
SELECT other_fields
FROM table1, table2
WHERE join_condition_table1_table2 AND some_other_condition
) AS subquery, table3
WHERE join_condition_subquery_table3
GROUP BY another_field
SELECT some_fields
FROM table1, table2, table3
WHERE
join_condition_table1_table2
AND join_condition_subquery_table3 -- actually rewrite this ans a join of either table1 and table3, or table2 and table3
AND some_other_condition
GROUP BY another_field
|
MySql GROUP BY using filesort - query optimization
Tag : mysql , By : ArmHead
Date : March 29 2020, 07:55 AM
I hope this helps . I have a table like this: , For this query: SELECT p.date_fact, UNIX_TIMESTAMP(p.date_fact),
COUNT(DISTINCT p.purchase_id) AS Num
FROM purchase p
WHERE p.date_fact >= '2017-01-01' AND
p.date_fact <= '2017-01-31' AND
p.fact_type = 3 AND
p.purchase_id_primary IS NULL
GROUP BY p.date_fact;
|
MySql group by optimization - avoid tmp table and/or filesort
Date : March 29 2020, 07:55 AM
With these it helps The relationship between these tables is 1:1, so, I asked me why is a group by required and I found some duplicated rows, 200 in 50000 rows. So, somehow, my system is inserting duplicates and someone put that group by (years ago) instead of seek of the bug. So, I will mark this as solved, more or less...
|