Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7880735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:12:55+00:00 2026-06-03T04:12:55+00:00

I have a legacy PHP application (uses no framework) – in places it has

  • 0

I have a legacy PHP application (uses no framework) – in places it has some real slowdown with some queries taking 8-10 seconds.

Below is the extract from one of these slow queries I can see that I am getting filesort which indicates that this is running slow for the reason (or at least I presume) – can anyone suggest how to optimize my queries to prevent using filesort? The table has around 600,000 rows (so its fairly large)

Schema added:
(MailList_Tags)
Field   Type    Null    Key Default Extra
MailListID  int(11)     PRI 0    
Tag varchar(60)     PRI      

(MailList)    
Field   Type    Null    Key Default Extra
MailListID  int(11)     PRI NULL    auto_increment
GroupID varchar(8)  YES     NULL     
HotelID varchar(8)  YES     NULL     
Title   varchar(20) YES     NULL     
FirstName   blob    YES     NULL     
LastName    blob    YES     NULL     
CompanyName varchar(200)    YES     NULL     
Address blob    YES     NULL     
Postcode    varchar(12) YES     NULL     
Country varchar(200)    YES     NULL     
Tel varchar(40) YES     NULL     
Fax varchar(40) YES     NULL     
Email   blob                 
md5digest   varchar(32)     UNI      
Sub1    int(1)      MUL 0    
Sub2    int(1)      MUL 0    
Sub3    int(1)      MUL 0    
OptInState  char(1)     MUL P    
UpdateDetailsState  char(1) YES     NULL     
Bounce  int(11)         0


EXPLAIN SELECT  `Tag` , COUNT( DISTINCT (
`MailList_Tags`.`MailListID`
) ) AS  `Count` 
FROM  `MailList` 
JOIN  `MailList_Tags` ON  `MailList`.`MailListID` =  `MailList_Tags`.`MailListID` 
WHERE HotelID =  'ca4b9ac9'
AND OptInState =  'V'
GROUP BY  `Tag`

id  select_type table   type    possible_keys   key key_len ref rows    Extra
1   SIMPLE  MailList_Tags   index   MailListID  MailListID  64  NULL    962583  Using index; Using filesort
1   SIMPLE  MailList    eq_ref  PRIMARY,OptInState  PRIMARY 4   user_db.MailList_Tags.MailListID    1   Using where
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T04:12:56+00:00Added an answer on June 3, 2026 at 4:12 am

    You need some indexes:

    • on table MailList_Tags, add a UNIQUE index on (Tag, MailListID)

    • on table MailList, add an index on (OptInState, HotelID, MailListID).

    Then try this query (changed COUNT( DISTINCT MailList_Tags.MailListID ) to COUNT(*), should produce the same result):

    SELECT  Tag 
         ,  COUNT( * )
              AS  `Count` 
    FROM  MailList 
      JOIN  MailList_Tags 
        ON  MailList.MailListID = MailList_Tags.MailListID 
    WHERE  HotelID =  'ca4b9ac9'
      AND  OptInState =  'V'
    GROUP BY  Tag
    

    or this one:

    SELECT  Tag 
         ,  COUNT(*)
              AS  `Count` 
    FROM  MailList 
    WHERE  EXISTS 
           ( SELECT  *
             FROM  MailList_Tags 
             WHERE  MailList.MailListID = MailList_Tags.MailListID 
               AND  HotelID =  'ca4b9ac9'
               AND  OptInState =  'V'
           )
    GROUP BY  Tag
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a legacy PHP application that uses the following URL structure /product_info.php?products_id=YYY where
I have a legacy PHP application which uses brackets in it's naming of form
Currently I have a legacy based non-MVC php framework which I need to update
We have an old legacy PHP application. Now I want to write a new
I have an issue whereby a client has some legacy environment (IIS 6 /
I got some legacy code that has this: <?PHP if(isset($_GET['pagina'])==homepage) { ?> HtmlCode1 <?php
I'm adding new features to a legacy application written in PHP that uses an
I have a legacy web application php4/mysql4 (MyISAM, db contains some cms, some user
I have a legacy web application php4/mysql4 (MyISAM, db contains some cms, some user
I have inherited some legacy PHP code what was written back when it was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.