Ik ben bezig met de ontwikkeling van een webapplicatie. We gebruiken PostgreSQL als database. Nou was ik bezig om een aantal kleine queries die in 1 pagina gebruikt worden, te combineren naar 1 grotere query om performance-winst te halen. Doel van de queries is om het aantal objecten dat een klant heeft terug te geven. Dit is de query:
Probleem is echter, dat door deze enkele query de pagina zo'n 7-8 keer (!) trager wordt dan met veel losse queries. Voorheen was de pagina in ongeveer 0.09 seconden opgebouwd, nu duurt het bijna 0.8 seconden!
Dus mijn vraag is, doe ik hier iets fout? Of ligt het aan PostgreSQL? De site draait op Solaris 9 (Sparc), PostgreSQL hebben we als sunfreeware package geinstalleerd (postgresql-8.0.1-sol9-sparc-local).
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| select count(distinct us.user_id) as person_count, count(distinct c2s.c2s_serv_id) as service_count, count(distinct doc.doc_id) as document_count, count(distinct pr1.peer_cust_id2) as peering_count_1, count(distinct pr2.peer_cust_id1) as peering_count_2, count(distinct cur.cur_rack_id) as rack_count, count(distinct po.port_id) as port_count, count(distinct ip.ipaddr_id) as ipaddress_count, count(distinct c2pa.c2pa_patch_id) as patch_count from tbl_customer as cu left outer join tbl_user2customer as u2c on cu.cust_id = u2c.u2c_cust_id left outer join tbl_user as us on (u2c.u2c_user_id = us.user_id AND us.user_auth_id IS NULL) left outer join tbl_customer2service as c2s on cu.cust_id = c2s.c2s_cust_id left outer join tbl_document as doc on cu.cust_id = doc.doc_cust_id left outer join tbl_peering AS pr1 ON cu.cust_id = pr1.peer_cust_id1 left outer join tbl_peering AS pr2 ON cu.cust_id = pr2.peer_cust_id2 left outer join tbl_customerrack AS cur ON cu.cust_id = cur.cur_cust_id left outer join tbl_port AS po ON cu.cust_id = po.port_cust_id left outer join tbl_ipaddress AS ip ON cu.cust_id = ip.ipaddr_cust_id left outer join tbl_customer2patch AS c2pa ON cu.cust_id = c2pa.c2pa_cust_id where cu.cust_id = 0 |
Probleem is echter, dat door deze enkele query de pagina zo'n 7-8 keer (!) trager wordt dan met veel losse queries. Voorheen was de pagina in ongeveer 0.09 seconden opgebouwd, nu duurt het bijna 0.8 seconden!
Dus mijn vraag is, doe ik hier iets fout? Of ligt het aan PostgreSQL? De site draait op Solaris 9 (Sparc), PostgreSQL hebben we als sunfreeware package geinstalleerd (postgresql-8.0.1-sol9-sparc-local).