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

  • Home
  • SEARCH
  • 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 1009661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:57:46+00:00 2026-05-16T08:57:46+00:00

I have a query of the form: select m.id from mytable m left outer

  • 0

I have a query of the form:

select m.id from mytable m
left outer join othertable o on o.m_id = m.id
    and o.col1 is not null and o.col2 is not null and o.col3 is not null
where o.id is null

The query returns a few hundred records, although the tables have millions of rows, and it takes forever to run (around an hour).

When I check my index statistics using:

select * from pg_stat_all_indexes
where schemaname <> 'pg_catalog' and (indexrelname like 'othertable_%' or indexrelname like 'mytable_%')

I see that only the index for othertable.m_id is being used, and that the indexes for col1..3 are not being used at all. Why is this?

I’ve read in a few places that PG has traditionally not been able to index NULL values. However, I’ve read this has supposedly changed since PG 8.3? I’m currently using PostgreSQL 8.4 on Ubuntu 10.04. Do I need to make a “partial” or “functional” index specifically to speed up IS NOT NULL queries, or is it already indexing NULLs and I’m just misunderstanding the problem?

  • 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-16T08:57:47+00:00Added an answer on May 16, 2026 at 8:57 am

    You could try a partial index:

    CREATE INDEX idx_partial ON othertable (m_id)
    WHERE (col1 is not null and col2 is not null and col3 is not null);
    

    From the docs: http://www.postgresql.org/docs/current/interactive/indexes-partial.html

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

Sidebar

Related Questions

I have a query of the following form: SELECT * FROM MyTable WHERE Timestamp
I have a multiple JOIN in the form of SELECT * FROM column1 LEFT
I have a query of this form: SELECT e.date, SUM(e.size) as bytes FROM entries
I have a SQL query of the form SELECT ... FROM A@DB1 a, B@DB1
I have a linq query. I have a bunch of parameters from a form
I have a form that shows results from a database query, these results can
I have a query in the form: select a, b, c, d, e, f,
I have a view named VIEW_FORM_SALE_SUBMISSION_INFO I have query as select a.FormSl from VIEW_FORM_SALE_SUBMISSION_INFO
I have query that is build from user's inputs ( passed via html form).
I have an SQL query that takes the following form: UPDATE foo SET flag=true

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.