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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:52:29+00:00 2026-05-20T18:52:29+00:00

I need an ANTI-JOIN (not exists SELECT something from table…/ left join table WHERE

  • 0

I need an ANTI-JOIN (not exists SELECT something from table…/ left join table WHERE table.id IS NULL) on the same table. Acutally I have an index to serve the not exists question, but the query planner chooses to use a bitmap heap scan.

The table has 100 Million rows, so doing a heap scan is messed up…

It would be really fast if Postgres could compare to the indicies. Does Postgres have to visit the table for this ANTI-JOIN?

I know the table has to be visited at some point to serve the MVCC, but why so early? Can NOT EXISTS only be fixed by the table, because it could miss something otherwise?

  • 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-20T18:52:30+00:00Added an answer on May 20, 2026 at 6:52 pm

    You’ll need to provide version details, and as jmz says EXPLAIN ANALYSE output to get any useful advice.

    Franz – don’t think whether it’s possible, test and know.

    This is v9.0:

    CREATE TABLE tl (i int, t text);
    CREATE TABLE tr (i int, t text);
    INSERT INTO tl SELECT s, 'text ' || s FROM generate_series(1,999999) s;
    INSERT INTO tr SELECT s, 'text ' || s FROM generate_series(1,999999) s WHERE s % 3 = 0;
    ALTER TABLE tl add primary key (i);
    CREATE INDEX tr_i_idx ON tr (i);
    ANALYSE;
    EXPLAIN ANALYSE SELECT i,t FROM tl LEFT JOIN tr USING (i) WHERE tr.i IS NULL;
                                                             QUERY PLAN                                                      
    -----------------------------------------------------------------------------------------------------------------------------
     Merge Anti Join  (cost=0.95..45611.86 rows=666666 width=15) (actual time=0.040..4011.970 rows=666666 loops=1)
       Merge Cond: (tl.i = tr.i)
       ->  Index Scan using tl_pkey on tl  (cost=0.00..29201.32 rows=999999 width=15) (actual time=0.017..1356.996 rows=999999 lo
       ->  Index Scan using tr_i_idx on tr  (cost=0.00..9745.27 rows=333333 width=4) (actual time=0.015..439.087 rows=333333 loop
     Total runtime: 4602.224 ms
    

    What you see will depend on your version, and the stats the planner sees.

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

Sidebar

Related Questions

Weird question, but I'm not sure if it's anti-pattern or not. Say I have
need ask you about some help. I have web app running in Net 2.0.
Need some help about with Memcache. I have created a class and want to
Hello I'm using visual studio 2008 with asp.net mvc 2. I need anti xss
We have quite a few validation methods that need to access repositories / database
According to anti-if campaign it is a best practice not to use ifs in
I have a definition list and I need to delete all the <dt> tags
I have plenty of java domain objects that I need to transform to DTOs.
I have this idea for a free backup application. The largest problem I need
I need to extract text-only content from my thesis document written in LaTeX for

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.