![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
Yes, I will subscribe to the performance list, but strictly speaking the behaviour described should be considered a bug. The assumptions made in deciding what the query optimisations will be seem all skewed, and the end result is that the system isn't useful in very common cases. =/ |
#4
| |||
| |||
|
|
I don't think your experience on this one query is descriptive of PostgreSQL in general. What I'm saying is that you most likely have a tuning problem, not a bug. |
#5
| |||
| |||
|
|
They PGSQL-PERFORMANCE list is really the appropriate place for performance issues like yours. Subscribe? |
#6
| |||
| |||
|
|
The following bug has been logged online: Bug reference: 1552 Logged by: Brian O'Reilly Email address: fade (AT) deepsky (DOT) com PostgreSQL version: 8.0.1 Operating system: Linux 2.6.11 Description: massive performance hit between 7.4 and 8.0.1 Details: When doing a lot of inserts to an empty table with a foreign key to another table, there is an incredible performance degredation issue on 8.0.1. I have a program that is inserting rows in an iterative loop, and in this form it inserts about 110,000 rows. On postgresql 7.4 on a debian machine it takes a shade over 2 minutes to complete. On an amd64 box running gentoo, it takes over an hour and fourty minutes to complete. The query plan on the debian host that completes quickly follows: |
|
the query optimiser seems to be setting a default strategy of doing sequential scans on an empty table, which is a fast strategy when the table is empty and not particularly full, but obviously on a large table the performance is O(N^2). This is clearly a bug. |
|
Please let me know if I can provide any more information. |
#7
| ||||
| ||||
|
|
The EXPLAINs you've enclosed are for SELECTs, yet your bug report describes INSERTs as being the things that are slow. [You may find better performance from using COPY] |
|
Also, your tests have compared two systems, so it might be that the hardware or configuration of one system is different from the other. |
|
If you could repeat the test on one single system, then this would assist in the diagnosis of this bug report. Also, if you could describe the workload that is giving you a problem more exactly, that would help. Specifically, can you confirm that you have run ANALYZE on the tables, and also give us some idea of numbers of rows in each table at the time you first run your programs. |
|
There is clearly a problem, but it is not yet clearly a bug. If it is a bug, we're interested in solving it as much as you. |
#8
| |||
| |||
|
|
One other thing which puzzled me: as a test, I tried modifying our script to spit out raw SQL statements instead of connecting to the database and performing the inserts itself. Normally, our script populates two tables in one pass, and then populates the third and fourth tables in a second pass. I massaged the SQL by hand to group the inserts together by table, so that the first table would be entirely populated, then the second, etc. When I ran this SQL script by piping it straight into psql, it finished in about four minutes. |
#9
| |||
| |||
|
|
Changing the order so that the referenced table is fully populated, or at least populated with more than a handful of pages of rows, before doing _any_ insert on a referencing table in the same session will avoid the misplan of the FK trigger queries, because when the first insert happens on a referencing table, there will be no reason for the planner to prefer a sequential scan. So this result is not surprising at all. |
#10
| |||
| |||
|
|
I'm still looking for an example that demonstrates why this is a common problem that we need to worry about. ISTM that if an FK reference is hit when there are still zero entries in the referenced table, that insertion will fail anyway, and so people wouldn't try to load data in such an order. |
|
We could band-aid this in 8.0 as previously suggested (have the planner assume > 0 pages when it sees actually 0 pages) but without seeing a concrete example I can't tell if that will fix the complaint or not. |
![]() |
| Thread Tools | |
| Display Modes | |
| |