I know that in general, joins are better that subselects. Is this true for postgresql also?
I have a simple recreation of a object hirarhcy:
- class table
- variable table (forign key to class)
- instance table (forign key to class)
- value table (forign keys to variable and insance)
To get the value of a variable for a specific instance, having the instance_id and the name of the variable, I'm doing a select on the value table and subselecting to get the id of the variable by its name.
Should I be using joints instead? OR does it not matter ?
Indexes are doing well with the subselects, Would switching to joins make the indexes uselss?
From what I have found, it does not seem to make a difference. The query parser thingy seems to produce the same explain plan using either subselect or a join...
I don't know - but maybe the re-writing of the query by the parser takes more time if you use subselects. I can't be sure, but there has to be some overheads somewhere, one has to be better than the other.