## Sequential Scans On Complex Query With UNION - see why this fails

From: Steve Tucknott PostGreSQL Sequential Scans On Complex Query With UNION - see why this fails 2006-01-02 09:10:45 1136193045.4179.1.camel@retsol1 (view raw, whole thread or download thread mbox) 2006-01-02 09:10:45 from Steve Tucknott  2006-01-11 21:03:27 from Steve Tucknott  2006-01-11 23:37:35 from Michael Glaesemann   2006-01-12 03:21:40 from Tom Lane    2006-01-12 03:48:27 from Michael Glaesemann     2006-01-12 04:42:18 from Tom Lane pgsql-novice
```
PostgreSql 8.0.3

I have a complex query that I want to read the data in a hierarchical
manner - ie from master table filtered rows to sub set1, from subset1 to
subset2 etc. The query is in the attached file, as is the explain. What
I do not understand is why I get sequential scans on certain tables - ie
the purchaseOrdDet, product, supplierProduct when each of the joins
linking the tables hits a valid 'record number' based index.
The query is trying to find all purchase orders within a period, then
all the lines for those orders, products for those lines etc. The union
selects from the supplierproduct/product tables on both sides - in one
case it uses the index and on the other does a sequential scan.

I am obviously doing something wrong in the structure of the query - any
ideas?

Also,...as a quick 'method' question..when writing embedded joins, which
syntax is easier for the optimiser? Should you do:

FROM table tableA AS A
JOIN tableB AS B
JOIN tableC AS C
JOIN tableD AS D
ON  C.joinD = D.join
JOIN tableE AS E
ON c.joinE = E.join
ON B.joinC = C.join
ON A.joinB = B.join

OR
FROM table tableA AS A
JOIN tableB AS B
ON A.joinB = B.join
JOIN tableC AS C
ON B.joinC = C.join
JOIN tableD AS D
ON  C.joinD = D.join
JOIN tableE AS E
ON c.joinE = E.join

OR is it immaterial and just a matter of style?

Regards,

Steve Tucknott

```

Attachment: SQL
Description: text/plain (3.3 KB)
Attachment: QUERYPLAN
Description: text/plain (15.2 KB)

### pgsql-novice by date

 Next: From: Frank Bax Date: 2006-01-02 14:49:32 Subject: Re: backup by schema Previous: From: First Last Date: 2006-01-02 09:09:39 Subject: can't log on to phppgadmin