Domanda

I'm very new to PostgreSQL, forgive me if something obvious is not clear for me. I have a database with ~450 million rows distributed across 6 tables (every table has primary key). When I run the following query:

SELECT * FROM "Payments" AS p
JOIN "PaymentOrders" AS po ON po."Id" = p."PaymentOrderId"
WHERE po."Id" = 1000

po."Id" is primary key. I just VACUUM ANALYZED whole database. You can see EXPLAIN ANALYZE details here. PaymentOrders table contains 40 million rows, while Payments contains 350 million rows. I'm running x64 PostgreSQL 9.2 on Windows 8 machine, I5 CPU (4 cores 3.3GHz), 8GB of RAM. Also you can see my postgresql.conf file here.

Anyone has any idea why this query causes a sequential scan on Payments table? Am I doing something wrong or PostgreSQL has some serious flaws? I started to seriously doubt in PostgreSQL query planner...

È stato utile?

Soluzione

Did you index both sides of the FOREIGN KEY relation? In particular, is there an index on Payments.PaymentOrderID?

Altri suggerimenti

Are po."Id" = p."PaymentOrderId" the same type? They need to match for the planner to use an index to join on them.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top