We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Single Query Making CP Unusable

Development and Programming

tylonius's avatar
tylonius
4 posts
13 years ago
tylonius's avatar tylonius

I have a site with millions of members, and EE’s search of the exp_members table is bringing the entire CP – and at times, the site – to its knees.

Whenever I try to add or edit any channel entry, I get this: http://www.htcdev.com/NewEntryStats.html

The specific query gumming up the works is this one:

SELECT `exp_members`.`member_id`, `exp_members`.`group_id`, `exp_members`.`username`, `exp_members`.`screen_name`, `exp_members`.`in_authorlist`
FROM (`exp_members`)
JOIN `exp_member_groups` ON `exp_member_groups`.`group_id` = `exp_members`.`group_id`
WHERE (exp_members.in_authorlist = "y" OR
 exp_member_groups.include_in_authorlist = "y")
AND `exp_members`.`group_id` = exp_member_groups.group_id
AND `exp_member_groups`.`site_id` =  '1'
ORDER BY `exp_members`.`screen_name` ASC, `exp_members`.`username` ASC

It’s taking a full three minutes to execute.

Can anyone help?

       
Marc Miller's avatar
Marc Miller
84 posts
13 years ago
Marc Miller's avatar Marc Miller

I have exactly the same problem with that query, but no solution yet (sorry)

We have just shy of 300K in our member database and it still causes problems. Our biggest member group - the default Members has a majority of those users and that group has:

Include Members in PUBLISH page multi-author list? NO Include Members in Site’s Member List? NO

But it doesn’t matter as that Query is still too huge.

EE 2.5.2 MSM site

I too am on the lookout for a fix for this.

       
Gareth Davies's avatar
Gareth Davies
491 posts
13 years ago
Gareth Davies's avatar Gareth Davies

Have you tried added database indexes to exp_members.in_authorlist and exp_member_groups.include_in_authorlist

       
Marc Miller's avatar
Marc Miller
84 posts
13 years ago
Marc Miller's avatar Marc Miller

Thanks Gareth, I attempted that and don’t think it had any effect.

First of all - I ended up deleting over 200K accounts that were created during a time period where our spam protection was pretty weak. Those 200K hadn’t logged in in over a year and had never made a comment or forum post - so we felt they were safe to remove while we debug this. I made a backup of the db in case.

So then, if I used the EXPLAIN SELECT query on the above questionable query, I get the result:

id  select_type  table  type  possible_keys  key  key_len  ref  rows  Extra
1 SIMPLE  exp_members  ALL  group_id  NULL NULL NULL 76921 Using filesort
1 SIMPLE  exp_member_groups  eq_ref  PRIMARY  PRIMARY  6 ee2.exp_members.group_id,const  1 Using where

Showing me that on exp_members, group_id is a possible key, but wasn’t used and the query had to be run against 76921 rows.

I ran:

ALTER TABLE exp_members ADD INDEX(in_authorlist);
ALTER TABLE exp_member_groups ADD INDEX(include_in_authorlist);

Then ran the EXPLAIN SELECT again and got:

1 SIMPLE  exp_members  ALL  group_id,in_authorlist  NULL NULL NULL 76921 Using filesort
1 SIMPLE  exp_member_groups  eq_ref  PRIMARY,include_in_authorlist  PRIMARY  6 ee2.exp_members.group_id,const  1 Using where

Nothing changed. The query against exp_members is still being run against every row.

So then I’m thinking, ok, maybe PRIMARY is the problem and I remove that from exp_member_groups - which is weird to have a primary key on it, since there aren’t any unique numbers in it in an MSM environment. Now, I’m not a database expert, but I don’t know how it’s possible to have a Primary Key without something unique to each row.

At any rate, removing the PRIMARY made things worse.

1  SIMPLE  exp_members  ALL  in_authorlist  NULL NULL NULL 76921  Using filesort
1  SIMPLE  exp_member_groups  ref  include_in_authorlist  ee2.exp_members.group_id  18  Using where

Now exp_member_groups is run against 18 rows where before it was just 6.

I couldn’t just add back a Primary Key without a unique number, so I had to create a new column with auto_increment and assign the primary to that column. Still - I can’t get the number of rows used by member_groups back to 6 anymore. Adding an index on the new ID column didn’t help.

So all in all - this is a bit of a failure as far as I can tell. In general, we’re doing ok with under 100K users, but I don’t know how to improve this query for if/when our members table grows to over 300K again.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.