• Rather than show me public and private posts, it seems on my site that this query is somehow ordering the data wrong when I am logged in as Administrator.

    Here’s the query when I’m logged in:

    SELECT SQL_CALC_FOUND_ROWS wp_posts.ID,wp_posts.post_status,wp_posts.post_date FROM wp_posts WHERE 1=1 AND wp_posts.post_type = ‘post’ AND (wp_posts.post_status = ‘publish’ OR wp_posts.post_status = ‘private’) ORDER BY wp_posts.post_date DESC LIMIT 0, 10;

    ERROR 2006 (HY000): MySQL server has gone away
    No connection. Trying to reconnect…
    Connection id: 8295177
    Current database: xxx

    +——+————-+———————+
    | ID | post_status | post_date |
    +——+————-+———————+
    | 7856 | publish | 2013-05-12 01:07:17 |
    | 7858 | publish | 2013-05-12 01:09:00 |
    | 7860 | publish | 2013-05-12 01:13:07 |
    | 7862 | publish | 2013-05-12 01:15:00 |
    | 7866 | publish | 2013-05-12 01:26:26 |
    | 7872 | publish | 2013-05-12 11:42:33 |
    | 7885 | publish | 2013-05-12 11:45:19 |
    | 7887 | publish | 2013-05-12 11:48:08 |
    | 7889 | publish | 2013-05-12 11:50:18 |
    | 7892 | publish | 2013-05-12 11:51:37 |
    +——+————-+———————+

    And here’s the query when not logged in:

    SELECT SQL_CALC_FOUND_ROWS wp_posts.ID,wp_posts.post_status,wp_posts.post_date FROM wp_posts WHERE 1=1 AND wp_posts.post_type = ‘post’ AND (wp_posts.post_status = ‘publish’) ORDER BY wp_posts.post_date DESC LIMIT 0, 10;ERROR 2006 (HY000): MySQL server has gone away
    No connection. Trying to reconnect…
    Connection id: 8297245
    Current database: xxx

    +——-+————-+———————+
    | ID | post_status | post_date |
    +——-+————-+———————+
    | 10976 | publish | 2013-06-08 23:46:49 |
    | 10971 | publish | 2013-06-08 23:44:05 |
    | 10965 | publish | 2013-06-08 23:39:27 |
    | 10959 | publish | 2013-06-08 23:35:09 |
    | 10954 | publish | 2013-06-08 23:32:55 |
    | 10948 | publish | 2013-06-08 23:29:21 |
    | 10942 | publish | 2013-06-08 23:25:15 |
    | 10937 | publish | 2013-06-08 23:18:25 |
    | 10932 | publish | 2013-06-08 23:14:31 |
    | 10927 | publish | 2013-06-08 23:08:03 |
    +——-+————-+———————+

    There are no private entries in the database:

    mysql> SELECT SQL_CALC_FOUND_ROWS wp_posts.ID,wp_posts.post_status,wp_posts.post_date FROM wp_posts WHERE 1=1 AND wp_posts.post_type = ‘post’ AND (wp_posts.post_status = ‘private’) ORDER BY wp_posts.post_date DESC LIMIT 0, 10;
    ERROR 2006 (HY000): MySQL server has gone away
    No connection. Trying to reconnect…
    Connection id: 8297776
    Current database: xxx

    Empty set (0.48 sec)

    Having debugged the queries using mysql explain, it seems that this is due to the broken query using a filesort on the index

    EXPLAIN SELECT SQL_CALC_FOUND_ROWS wp_posts.ID,wp_posts.post_status,wp_posts.post_date FROM wp_posts WHERE 1=1 AND wp_posts.post_type = ‘post’ AND (wp_posts.post_status = ‘publish’ OR wp_posts.post_status = ‘private’) ORDER BY wp_posts.post_date DESC LIMIT 0, 10\G;
    ERROR 2006 (HY000): MySQL server has gone away
    No connection. Trying to reconnect…
    Connection id: 8300465
    Current database: xxx

    *************************** 1. row ***************************
    id: 1
    select_type: SIMPLE
    table: wp_posts
    type: range
    possible_keys: type_status_date
    key: type_status_date
    key_len: 124
    ref: NULL
    rows: 2259
    Extra: Using where; Using index; Using filesort

    Rather than the regular query:

    EXPLAIN EXTENDED SELECT SQL_CALC_FOUND_ROWS wp_posts.ID,wp_posts.post_status,wp_posts.post_date FROM wp_posts WHERE 1=1 AND wp_posts.post_type = ‘post’ AND (wp_posts.post_status = ‘publish’) ORDER BY wp_posts.post_date DESC LIMIT 0, 10\G;
    ERROR 2006 (HY000): MySQL server has gone away
    No connection. Trying to reconnect…
    Connection id: 8300205
    Current database: xxx

    *************************** 1. row ***************************
    id: 1
    select_type: SIMPLE
    table: wp_posts
    type: ref
    possible_keys: type_status_date
    key: type_status_date
    key_len: 124
    ref: const,const
    rows: 2258
    Extra: Using where; Using index
    1 row in set, 1 warning (0.45 sec)

    How can this be fixed?
    Thanks!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Can't see my latest posts when logged in as Administrator.’ is closed to new replies.