[wp-hackers] Seeking SQL advice to identify performance problem
Mike Walsh
mpwalsh8 at gmail.com
Wed Jun 20 12:42:04 UTC 2012
I have a query that I have used in a couple plugins that someone on this
mailing list helped me with several years ago. I want to retrieve the list
of Users, including their ID, username, display name, first name, and last
name so I can present the information in a form in a way that is easily
readable. This is the query I am using:
SELECT DISTINCT ID, display_name, user_email, user_login, first_name,
last_name FROM wp_usermeta, wp_users
LEFT JOIN ( SELECT user_id AS uid, meta_value AS first_name FROM
wp_usermeta WHERE meta_key = 'first_name' ) AS metaF ON wp_users.ID =
metaF.uid LEFT JOIN ( SELECT user_id AS uid, meta_value AS last_name
FROM wp_usermeta WHERE meta_key = 'last_name' ) AS metaL ON
wp_users.ID = metaL.uid WHERE (id<>1) ORDER BY last_name
In my development area this query takes almost 4 minutes to run and my
WordPress database has 650 users defined. There is very little other
content in the database besides some test posts.
--
Mike Walsh - mpwalsh8 at gmail.com
More information about the wp-hackers
mailing list