Andy's Blog » » WordPress2.3还是很慢

WordPress2.3还是很慢

首页执行了50次查询,能不慢吗
来看看它都干了些什么
很明显,在循环里执行了SQL查询,这是大忌
还有很多可以合并或简化的查询
wordpress2.3里的wp-db.php终于指定了数据库编码
认真看看这些SQL,对写程序还是有帮助的

array(50) {
  [0]=>
  array(2) {
    [0]=>
    string(16) "SET NAMES 'utf8'"
    [1]=>
    float(0.000114917755127)
  }
  [1]=>
  array(2) {
    [0]=>
    string(65) "SELECT option_value FROM wp_options WHERE option_name = 'siteurl'"
    [1]=>
    float(8.29696655273E-5)
  }
  [2]=>
  array(2) {
    [0]=>
    string(71) "SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes'"
    [1]=>
    float(0.000236034393311)
  }
  [3]=>
  array(2) {
    [0]=>
    string(84) "SELECT option_value FROM wp_options WHERE option_name = 'widget_stags_cloud' LIMIT 1"
    [1]=>
    float(0.0001220703125)
  }
  [4]=>
  array(2) {
    [0]=>
    string(65) "SELECT option_value FROM wp_options WHERE option_name = 'siteurl'"
    [1]=>
    float(6.69956207275E-5)
  }
  [5]=>
  array(2) {
    [0]=>
    string(77) "SELECT option_value FROM wp_options WHERE option_name = 'widget_text' LIMIT 1"
    [1]=>
    float(6.41345977783E-5)
  }
  [6]=>
  array(2) {
    [0]=>
    string(76) "SELECT option_value FROM wp_options WHERE option_name = 'widget_rss' LIMIT 1"
    [1]=>
    float(6.19888305664E-5)
  }
  [7]=>
  array(2) {
    [0]=>
    string(50) "SELECT ID FROM wp_users WHERE user_login = 'admin'"
    [1]=>
    float(6.89029693604E-5)
  }
  [8]=>
  array(2) {
    [0]=>
    string(45) "SELECT * FROM wp_users WHERE ID = '1' LIMIT 1"
    [1]=>
    float(8.51154327393E-5)
  }
  [9]=>
  array(2) {
    [0]=>
    string(64) "SELECT meta_key, meta_value FROM wp_usermeta WHERE user_id = '1'"
    [1]=>
    float(6.103515625E-5)
  }
  [10]=>
  array(2) {
    [0]=>
    string(181) " SELECT SQL_CALC_FOUND_ROWS  wp_posts.* FROM wp_posts  WHERE 1=1  AND post_type = 'post' AND (post_status = 'publish' OR post_status = 'private')  ORDER BY post_date DESC LIMIT 5, 5"
    [1]=>
    float(2.38655519485)
  }
  [11]=>
  array(2) {
    [0]=>
    string(19) "SELECT FOUND_ROWS()"
    [1]=>
    float(0.000230073928833)
  }
  [12]=>
  array(2) {
    [0]=>
    string(332) "SELECT t.*, tt.*, tr.object_id FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category', 'bsuite_search', 'post_tag') AND tr.object_id IN (21260, 21259, 21258, 21257, 21256) ORDER BY t.name ASC"
    [1]=>
    float(0.550291061401)
  }
  [13]=>
  array(2) {
    [0]=>
    string(128) "SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN(21260,21259,21258,21257,21256) ORDER BY post_id, meta_key"
    [1]=>
    float(0.000447988510132)
  }
  [14]=>
  array(2) {
    [0]=>
    string(93) "SELECT option_value FROM wp_options WHERE option_name = 'statpress_collectloggeduser' LIMIT 1"
    [1]=>
    float(9.79900360107E-5)
  }
  [15]=>
  array(2) {
    [0]=>
    string(549) "
SELECT DISTINCT terms.name AS name, terms.term_id AS term_id
FROM wp_posts AS posts
INNER JOIN wp_term_relationships AS term_relationships ON (posts.ID = term_relationships.object_id)
INNER JOIN wp_term_taxonomy AS term_taxonomy ON (term_relationships.term_taxonomy_id = term_taxonomy.term_taxonomy_id)
INNER JOIN wp_terms AS terms ON (term_taxonomy.term_id = terms.term_id)
WHERE term_taxonomy.taxonomy = 'post_tag'
AND ( posts.ID IN ('21260', '21259', '21258', '21257', '21256') )
ORDER BY term_taxonomy.count DESC"
    [1]=>
    float(0.00131011009216)
  }
  [16]=>
  array(2) {
    [0]=>
    string(105) "SELECT * FROM wp_posts  WHERE (post_type = 'page' AND post_status = 'publish')    ORDER BY menu_order ASC"
    [1]=>
    float(0.000112771987915)
  }
  [17]=>
  array(2) {
    [0]=>
    string(155) "SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = 'category' AND t.term_id = '72' LIMIT 1"
    [1]=>
    float(0.000123023986816)
  }
  [18]=>
  array(2) {
    [0]=>
    string(154) "SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = 'category' AND t.term_id = '1' LIMIT 1"
    [1]=>
    float(7.89165496826E-5)
  }
  [19]=>
  array(2) {
    [0]=>
    string(155) "SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = 'category' AND t.term_id = '54' LIMIT 1"
    [1]=>
    float(6.98566436768E-5)
  }
  [20]=>
  array(2) {
    [0]=>
    string(639) "
SELECT DISTINCT p.post_title, p.comment_count, p.post_date, p.ID, COUNT(tr.object_id) as counter 
FROM wp_posts AS p
INNER JOIN wp_term_relationships AS tr ON (p.ID = tr.object_id)
INNER JOIN wp_term_taxonomy AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
WHERE tt.taxonomy = 'post_tag'
AND (tt.term_id IN ("8420", "39565", "39349", "8423", "39566", "39567", "1433", "3007", "3580", "8446"))
AND p.ID <> 21260
AND p.post_status = 'publish'
AND p.post_date < '2007-12-08 01:39:02'

AND p.post_type IN ('page', 'post')
GROUP BY tr.object_id
ORDER BY p.post_date DESC
LIMIT 0, 5"
    [1]=>
    float(0.493484973907)
  }
  [21]=>
  array(2) {
    [0]=>
    string(49) "SELECT * FROM wp_posts WHERE ID = '21262' LIMIT 1"
    [1]=>
    float(0.00648498535156)
  }
  [22]=>
  array(2) {
    [0]=>
    string(49) "SELECT * FROM wp_posts WHERE ID = '21217' LIMIT 1"
    [1]=>
    float(0.000124931335449)
  }
  [23]=>
  array(2) {
    [0]=>
    string(49) "SELECT * FROM wp_posts WHERE ID = '21205' LIMIT 1"
    [1]=>
    float(0.0436470508575)
  }
  [24]=>
  array(2) {
    [0]=>
    string(49) "SELECT * FROM wp_posts WHERE ID = '21165' LIMIT 1"
    [1]=>
    float(0.000373125076294)
  }
  [25]=>
  array(2) {
    [0]=>
    string(49) "SELECT * FROM wp_posts WHERE ID = '21069' LIMIT 1"
    [1]=>
    float(0.000136852264404)
  }
  [26]=>
  array(2) {
    [0]=>
    string(625) "
SELECT DISTINCT p.post_title, p.comment_count, p.post_date, p.ID, COUNT(tr.object_id) as counter 
FROM wp_posts AS p
INNER JOIN wp_term_relationships AS tr ON (p.ID = tr.object_id)
INNER JOIN wp_term_taxonomy AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
WHERE tt.taxonomy = 'post_tag'
AND (tt.term_id IN ("21535", "180", "39559", "39560", "39561", "39562", "39563", "39564"))
AND p.ID <> 21259
AND p.post_status = 'publish'
AND p.post_date < '2007-12-08 01:39:02'

AND p.post_type IN ('page', 'post')
GROUP BY tr.object_id
ORDER BY p.post_date DESC
LIMIT 0, 5"
    [1]=>
    float(0.726358175278)
  }
  [27]=>
  array(2) {
    [0]=>
    string(49) "SELECT * FROM wp_posts WHERE ID = '21245' LIMIT 1"
    [1]=>
    float(0.000157117843628)
  }
  [28]=>
  array(2) {
    [0]=>
    string(49) "SELECT * FROM wp_posts WHERE ID = '21203' LIMIT 1"
    [1]=>
    float(0.000108957290649)
  }
  [29]=>
  array(2) {
    [0]=>
    string(49) "SELECT * FROM wp_posts WHERE ID = '21164' LIMIT 1"
    [1]=>
    float(0.000163078308105)
  }
  [30]=>
  array(2) {
    [0]=>
    string(49) "SELECT * FROM wp_posts WHERE ID = '21160' LIMIT 1"
    [1]=>
    float(0.000108003616333)
  }
  [31]=>
  array(2) {
    [0]=>
    string(49) "SELECT * FROM wp_posts WHERE ID = '21122' LIMIT 1"
    [1]=>
    float(0.000111818313599)
  }
  [32]=>
  array(2) {
    [0]=>
    string(580) "
SELECT DISTINCT p.post_title, p.comment_count, p.post_date, p.ID, COUNT(tr.object_id) as counter 
FROM wp_posts AS p
INNER JOIN wp_term_relationships AS tr ON (p.ID = tr.object_id)
INNER JOIN wp_term_taxonomy AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
WHERE tt.taxonomy = 'post_tag'
AND (tt.term_id IN ("928", "39558", "26061"))
AND p.ID <> 21258
AND p.post_status = 'publish'
AND p.post_date < '2007-12-08 01:39:03'

AND p.post_type IN ('page', 'post')
GROUP BY tr.object_id
ORDER BY p.post_date DESC
LIMIT 0, 5"
    [1]=>
    float(0.0810210704803)
  }
  [33]=>
  array(2) {
    [0]=>
    string(49) "SELECT * FROM wp_posts WHERE ID = '20951' LIMIT 1"
    [1]=>
    float(0.000141859054565)
  }
  [34]=>
  array(2) {
    [0]=>
    string(49) "SELECT * FROM wp_posts WHERE ID = '20070' LIMIT 1"
    [1]=>
    float(0.0001060962677)
  }
  [35]=>
  array(2) {
    [0]=>
    string(49) "SELECT * FROM wp_posts WHERE ID = '19771' LIMIT 1"
    [1]=>
    float(0.000283002853394)
  }
  [36]=>
  array(2) {
    [0]=>
    string(49) "SELECT * FROM wp_posts WHERE ID = '19584' LIMIT 1"
    [1]=>
    float(0.000124931335449)
  }
  [37]=>
  array(2) {
    [0]=>
    string(663) "
SELECT DISTINCT p.post_title, p.comment_count, p.post_date, p.ID, COUNT(tr.object_id) as counter 
FROM wp_posts AS p
INNER JOIN wp_term_relationships AS tr ON (p.ID = tr.object_id)
INNER JOIN wp_term_taxonomy AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
WHERE tt.taxonomy = 'post_tag'
AND (tt.term_id IN ("35282", "35283", "35285", "39550", "39551", "39552", "39553", "35287", "39554", "39555", "39556", "39557"))
AND p.ID <> 21257
AND p.post_status = 'publish'
AND p.post_date < '2007-12-08 01:39:03'

AND p.post_type IN ('page', 'post')
GROUP BY tr.object_id
ORDER BY p.post_date DESC
LIMIT 0, 5"
    [1]=>
    float(0.00152516365051)
  }
  [38]=>
  array(2) {
    [0]=>
    string(49) "SELECT * FROM wp_posts WHERE ID = '20074' LIMIT 1"
    [1]=>
    float(0.000209808349609)
  }
  [39]=>
  array(2) {
    [0]=>
    string(49) "SELECT * FROM wp_posts WHERE ID = '20053' LIMIT 1"
    [1]=>
    float(0.000186920166016)
  }
  [40]=>
  array(2) {
    [0]=>
    string(626) "
SELECT DISTINCT p.post_title, p.comment_count, p.post_date, p.ID, COUNT(tr.object_id) as counter 
FROM wp_posts AS p
INNER JOIN wp_term_relationships AS tr ON (p.ID = tr.object_id)
INNER JOIN wp_term_taxonomy AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
WHERE tt.taxonomy = 'post_tag'
AND (tt.term_id IN ("2868", "39543", "39544", "39545", "39546", "39547", "39548", "39549"))
AND p.ID <> 21256
AND p.post_status = 'publish'
AND p.post_date < '2007-12-08 01:39:03'

AND p.post_type IN ('page', 'post')
GROUP BY tr.object_id
ORDER BY p.post_date DESC
LIMIT 0, 5"
    [1]=>
    float(0.0350749492645)
  }
  [41]=>
  array(2) {
    [0]=>
    string(49) "SELECT * FROM wp_posts WHERE ID = '15383' LIMIT 1"
    [1]=>
    float(0.000326871871948)
  }
  [42]=>
  array(2) {
    [0]=>
    string(49) "SELECT * FROM wp_posts WHERE ID = '10521' LIMIT 1"
    [1]=>
    float(0.000195026397705)
  }
  [43]=>
  array(2) {
    [0]=>
    string(48) "SELECT * FROM wp_posts WHERE ID = '9757' LIMIT 1"
    [1]=>
    float(0.000190019607544)
  }
  [44]=>
  array(2) {
    [0]=>
    string(132) "SELECT COUNT(DISTINCT ID) FROM wp_posts  WHERE 1=1  AND post_type = 'post' AND (post_status = 'publish' OR post_status = 'private') "
    [1]=>
    float(9.79900360107E-5)
  }
  [45]=>
  array(2) {
    [0]=>
    string(151) "SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('category')  ORDER BY t.name ASC "
    [1]=>
    float(0.000205039978027)
  }
  [46]=>
  array(2) {
    [0]=>
    string(225) "SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM wp_posts  WHERE post_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC"
    [1]=>
    float(0.000332117080688)
  }
  [47]=>
  array(2) {
    [0]=>
    string(177) "SELECT *  , IF (DATE_ADD(link_updated, INTERVAL 120 MINUTE) >= NOW(), 1,0) as recently_updated   FROM wp_links  WHERE 1=1 AND link_visible = 'Y'    ORDER BY wp_links.link_id ASC"
    [1]=>
    float(0.000550985336304)
  }
  [48]=>
  array(2) {
    [0]=>
    string(290) "SELECT ID, comment_ID, comment_content, comment_author, comment_author_url, post_title FROM wp_comments LEFT JOIN wp_posts ON wp_posts.ID=wp_comments.comment_post_ID WHERE post_status IN ('publish','static') AND post_password ='' AND comment_approved = '1' ORDER BY comment_ID DESC LIMIT 10"
    [1]=>
    float(0.0001060962677)
  }
  [49]=>
  array(2) {
    [0]=>
    string(45) "SELECT * FROM wp_posts WHERE ID = '1' LIMIT 1"
    [1]=>
    float(9.98973846436E-5)
  }
}

Incoming search terms:

Tags:

本文地址: http://www.21andy.com/new/20071208/715.html

1 评论 to “PHP开源CMS之MODx”

  1. Eric 于 2007-12-27 01:33:47 发表:

    不知道怎么优化,感觉wp慢死了
    mysql要用5秒多……