Good time of the day!
There are three tables:
CREATE big (
id int4 PRIMARY KEY,
ref1 int4,
ref2 int4,
...
);
CREATE ref1 (
id int4 PRIMARY KEY,
...
);
CREATE ref2 (
id int4 PRIMARY KEY,
...
);
Tables ref1 and ref2 are small, like 10-15 records. Table big is
large. Often I need to get data from all tables. Which way is better
in terms on performance:
SELECT big.*, ref1.*, ref2.* FROM big, ref1, ref2 WHERE big.ref1 =
ref1.id AND big.ref2 = ref2.id AND ...
OR make 3 separate queries like, say
SELECT * FROM big WHERE ...
and then in the loop select corresponding data from small tables?
And more general question: how queries affect performance? Which way
is better: run two queries which will return, say, 5 records each, or
run one query which will return, say, 20 records and then drop
unneeded records in my backend application?
Best regards,
Dmitri ( mailto:dmitri@listsoft.ru )
New SOFT daily (RUS): http://www.listsoft.ru/
(ENG): http://www.listsoft.com/
Articles, tips : http://www.diskovod.ru/
---
Ошибок не прощают женщины и тетрис на 9й скорости.