Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2003
    Location
    Issaquah, WA
    Posts
    2

    Unanswered: Subselect or Join

    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?

    much rewriting to do if so
    Last edited by ahmadster; 12-09-03 at 18:11.

  2. #2
    Join Date
    Feb 2002
    Location
    San Francisco, CA
    Posts
    441
    Check the explain plan for the query;

    Code:
    explain
    select *
    from x
    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.
    Last edited by rhs98; 12-10-03 at 12:28.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •