![]() | |
#1
| |||
| |||
|
|
Id | Operation | Name | Rows | Cost (%CPU)| Time | |
|
0 | SELECT STATEMENT | | 1 | 157K (1)| 00:31:25 | 1 | SORT AGGREGATE | | 1 | | 2 | MERGE JOIN CARTESIAN | | 7529K| 157K (1)| 00:31:25 | 3 | MERGE JOIN CARTESIAN | | 537K| 11224 (1)| 00:02:15 | 4 | MERGE JOIN CARTESIAN | | 38416 | 808 (1)| 00:00:10 | 5 | MERGE JOIN CARTESIAN | | 2744 | 62 (0)| 00:00:01 | 6 | MERGE JOIN CARTESIAN | | 196 | 7 (0)| 00:00:01 | 7 | INDEX FULL SCAN | PK_EMP | 14 | 1 (0)| 00:00:01 | 8 | BUFFER SORT | | 14 | 6 (0)| 00:00:01 | 9 | INDEX FAST FULL SCAN| PK_EMP | 14 | 0 (0)| 00:00:01 | 10 | BUFFER SORT | | 14 | 62 (0)| 00:00:01 | 11 | INDEX FAST FULL SCAN | PK_EMP | 14 | 0 (0)| 00:00:01 | 12 | BUFFER SORT | | 14 | 808 (1)| 00:00:10 | 13 | INDEX FAST FULL SCAN | PK_EMP | 14 | 0 (0)| 00:00:01 | 14 | BUFFER SORT | | 14 | 11224 (1)| 00:02:15 | 15 | INDEX FAST FULL SCAN | PK_EMP | 14 | 0 (0)| 00:00:01 | 16 | BUFFER SORT | | 14 | 157K (1)| 00:31:25 | 17 | INDEX FAST FULL SCAN | PK_EMP | 14 | 0 (0)| 00:00:01 | |
#2
| |||
| |||
|
|
Battleground was a machine running CentOS 5.5 and the two towers were 2 databases. First, PostgreSQL 8.4.4: |
#3
| |||
| |||
|
|
Battleground was a machine running CentOS 5.5 and the two towers were 2 databases. First, PostgreSQL 8.4.4: scott=# select count(*) from emp e1,emp e2, emp e3, emp e4,emp e5, emp e6; count --------- 7529536 (1 row) Time: 2127.345 ms Now, Oracle 11.2.0.1 with the April patch: SQL> set autotrace on SQL> select count(*) from emp e1,emp e2, emp e3, emp e4,emp e5, emp e6; COUNT(*) ---------- 7529536 Elapsed: 00:00:00.85 Both databases have current statistics, the data is exactly the same, as shown by the results. Oracle finished in 0.85 second (850 milliseconds) while PostgreSQL took 2127.345 ms, 2.5 times slower than Oracle. The difference that is obvious is the access path: Postgres chose nested loops, while Oracle chose merge join and utilized the primary key for the table. Postgres, apparently cannot do "fast full scan" of an index and doesn't know how to utilize the primary key in cases like this. However, my gripe is that the optimizer should have selected merge join, just like Oracle did. In this case, nested loops are definitely the wrong choice. Rule based optimizers, the kind of the optimizer that takes into consideration only the structure of the table, usually ends up being dominated by the nested loops method. Nested loops method usually dominates the OLTP type applications but can really mess up large reports. I am under the impression that Postgres query planner is geared toward the OLTP type of the database. Maybe a new parameter is needed that would somehow shift gears to "data warehouse use", on demand? I have to say, the advantage is still on the side of Sauron. |
#4
| |||
| |||
|
|
I don't have enough insight into PostgreSQL yet but another explanation would be that developers did not bother to optimize for such an artificial query. Or did you derive this from some realistic use case? Kind regards robert |
![]() |
| Thread Tools | |
| Display Modes | |
| |