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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:36:47+00:00 2026-06-02T06:36:47+00:00

I have a query which is equi-joining two tables, TableA and TableB using a

  • 0

I have a query which is equi-joining two tables, TableA and TableB using a nested loop. Because of the “equi”-join contraint, all rows returned in the result will therefore correspond to at least one row from each of these two tables. However, according to the plan (EXPLAIN ANALYZE) the actual rows count is 0 from TableB, even though a row is returned in the final result. How can the actual rows count equal zero here?

Here is the execution plan:

=> explain analyze select p.id, p.title, s.count from products p, stock s where p.id = s.p_id and s.w_id = 6 and p.type = 9 and s.count > 0 order by p.title;
                                                          QUERY PLAN                                                          
------------------------------------------------------------------------------------------------------------------------------
 Sort  (cost=42.42..42.42 rows=2 width=36) (actual time=0.198..0.199 rows=1 loops=1)
   Sort Key: p.title
   Sort Method: quicksort  Memory: 25kB
   ->  Nested Loop  (cost=0.00..42.41 rows=2 width=36) (actual time=0.170..0.181 rows=1 loops=1)
         ->  Seq Scan on products p  (cost=0.00..9.25 rows=4 width=32) (actual time=0.068..0.106 rows=4 loops=1)
               Filter: (type = 9)
         ->  Index Scan using stock_pk on stock s  (cost=0.00..8.28 rows=1 width=8) (actual time=0.015..0.015 rows=0 loops=4)
               Index Cond: ((w_id = 6) AND (p_id = p.id))
               Filter: (count > 0)
 Total runtime: 0.290 ms

And the two table definitions… The products table first:

=> \d products
           Table "public.products"
 Column |          Type          | Modifiers 
--------+------------------------+-----------
 id     | integer                | not null
 title  | character varying(100) | 
 type   | integer                | 
 price  | double precision       | 
 filler | character(500)         | 
Indexes:
    "products_pkey" PRIMARY KEY, btree (id)
    "products_type_idx" btree (type)
Referenced by:
    TABLE "orderline" CONSTRAINT "orderline_p_id_fkey" FOREIGN KEY (p_id) REFERENCES products(id)
    TABLE "stock" CONSTRAINT "stock_p_id_fkey" FOREIGN KEY (p_id) REFERENCES products(id)

The stock table:

=> \d stock
     Table "public.stock"
 Column |  Type   | Modifiers 
--------+---------+-----------
 w_id   | integer | not null
 p_id   | integer | not null
 count  | integer | 
Indexes:
    "stock_pk" PRIMARY KEY, btree (w_id, p_id)
    "stock_p_id_idx" btree (p_id)
Foreign-key constraints:
    "stock_p_id_fkey" FOREIGN KEY (p_id) REFERENCES products(id)
    "stock_w_id_fkey" FOREIGN KEY (w_id) REFERENCES warehouses(id)
  • 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-02T06:36:50+00:00Added an answer on June 2, 2026 at 6:36 am

    The actual rows of the inner index scan is the average number of rows returned in each call of it.

    Looking at http://www.postgresql.org/docs/current/static/using-explain.html:

    In some query plans, it is possible for a subplan node to be executed more than once. For example, the inner index scan is executed once per outer row in the above nested-loop plan. In such cases, the loops value reports the total number of executions of the node, and the actual time and rows values shown are averages per-execution. This is done to make the numbers comparable with the way that the cost estimates are shown. Multiply by the loops value to get the total time actually spent in the node.

    I’m not sure how it’s rounded (I’m guessing down to the nearest int, after averaging), but it might be that most rows in products don’t have a corresponding row in stock.

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

Sidebar

Related Questions

I have a query which searches two separate fields in the same table... looking
I have two tables I want to join. I want all of the categories
I have query which returns single value (i.e) count. I'm exceuting it using the
I have a query which joins 6 tables, produces 800,000 rows, and inserts them
I have a query which involves 2 tables 'Coupons' and 'CouponUsedLog' in SQL Server,
I have a query which retrives two colums of multiple rows from the db.I
I have a query which produces a list of orders like this: Invoice Description
I have this query which works correctly in MySQL. More background on it here
I have a query which returns a series of cells of data from a
I have a query which part of a SP which is executed fairly regularly,

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.