﻿id,summary,reporter,owner,description,type,status,priority,milestone,component,version,severity,resolution,keywords,cc
21051,Database query needs optimization - function post_exists,arpit.tambi.in,,"Function post_exists in /wp-admin/includes/post.php is causing full table scans and sometimes it takes upto 30 seconds when there are millions of records in wp_posts table.

Sample query -

{{{
# Time: 120623  2:16:28
# User@Host: test[test] @ localhost []
# Query_time: 17  Lock_time: 0  Rows_sent: 0  Rows_examined: 13952234
SELECT ID FROM wp_posts WHERE 1=1 AND post_title = 'MIO WALKBLK'AND post_content = 'Mio Walk Black MENS HEART RATE DIGITAL FACE<br /><br /> Brand: MIO<br /> Style: HRM<br /> Size: Mens<br /> Attachement: Black Resin Band';
}}}

On running EXPLAIN output generated is

{{{
id 	select_type 	table 	type 	possible_keys 	key 	key_len 	ref 	rows 	Extra
1 	SIMPLE 	wp_posts 	ALL 	NULL	NULL	NULL	NULL	13952445 	Using where
}}}

Clearly its not making use of any index on wp_posts and thus causes full table scans and slow queries.

Suggestions:
More parameters like 'post_type', 'post_author', and 'post_category' can be added to improve functionality of post_exists function and this might also improve performance of database queries.",enhancement,new,normal,Awaiting Review,Performance,3.4,normal,,,
