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 4605330
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:25:03+00:00 2026-05-22T00:25:03+00:00

SELECT count(*) FROM contacts_lists JOIN plain_contacts ON contacts_lists.contact_id = plain_contacts.contact_id JOIN contacts ON contacts.id

  • 0
SELECT count(*) 
FROM contacts_lists 
     JOIN plain_contacts 
          ON contacts_lists.contact_id = plain_contacts.contact_id 
     JOIN contacts 
          ON contacts.id = plain_contacts.contact_id 
WHERE plain_contacts.has_email 
      AND NOT contacts.email_bad 
      AND NOT contacts.email_unsub 
      AND contacts_lists.list_id =67339

how can i optimize this query.. could you please explain…

  • 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-05-22T00:25:04+00:00Added an answer on May 22, 2026 at 12:25 am

    Reformatting your query plan for clarity:

    QUERY PLAN Aggregate (cost=126377.96..126377.97 rows=1 width=0)
      -> Hash Join (cost=6014.51..126225.38 rows=61033 width=0)
         Hash Cond: (contacts_lists.contact_id = plain_contacts.contact_id)
        -> Hash Join (cost=3067.30..121828.63 rows=61033 width=8)
           Hash Cond: (contacts_lists.contact_id = contacts.id)
          -> Index Scan using index_contacts_lists_on_list_id_and_contact_id
             on contacts_lists (cost=0.00..116909.97 rows=61033 width=4)
             Index Cond: (list_id = 66996)
             -> Hash (cost=1721.41..1721.41 rows=84551 width=4)
             -> Seq Scan on contacts (cost=0.00..1721.41 rows=84551 width=4)
                Filter: ((NOT email_bad) AND (NOT email_unsub))
                -> Hash (cost=2474.97..2474.97 rows=37779 width=4)
                -> Seq Scan on plain_contacts (cost=0.00..2474.97 rows=37779 width=4)
                   Filter: has_email
    

    Two partial indexes might eliminate seq scans depending on your data distribution:

    -- if many contacts have bad emails or are unsubscribed:
    CREATE INDEX contacts_valid_email_idx ON contacts (id)
    WHERE (NOT email_bad AND NOT email_unsub);
    
    -- if many contacts have no email:
    CREATE INDEX plain_contacts_valid_email_idx ON plain_contacts (id)
    WHERE (has_email);
    

    You might be missing an index on a foreign key:

    CREATE INDEX plain_contacts_contact_id_idx ON plain_contacts (contact_id);
    

    Last but not least if you’ve never analyzed your data, you need to run:

    VACUUM ANALYZE;
    

    If it’s still slow once all that is done, there isn’t much you can do short of merging your plain_contacts and your contacts tables: getting the above query plan in spite of the above indexes means most/all of your subscribers are subscribed to that particular list — in which case the above query plan is the fastest you’ll get.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Example: select count(*) from my table where column1 is not null and (column1 =
I am running a simple join query select count(*) from t1 join t2 on
I have the following query: SELECT COUNT(*) FROM FirstTable ft INNER JOIN SecondTable st
SELECT * from `employees` a LEFT JOIN (SELECT phone1 p1, count(*) c, FROM `employees`
TOPIC_COUNT_SQL = SELECT COUNT(*) FROM topics_topic WHERE topics_topic.object_id = maps_map.id AND topics_topic.content_type_id = %s
I want to do SELECT count(*) FROM users where created_at within 3 days ago
SET @v1 := SELECT COUNT(*) FROM user_rating; SELECT @v1 When I execute this query
I have this query: SELECT COUNT(articles.id) AS count FROM articles, xml_documents, streams WHERE articles.xml_document_id
When I run the query : select count(*) from (select idCover from x90..dimCover group
I have the following two queries: select count(*) from segmentation_cycle_recipients scr , segmentation_instance si

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.