Thread: joins and indexes -- a=b or b=a?

joins and indexes -- a=b or b=a?

From
will trillich
Date:
if you have a main table on which you're doing a linear scan:

    create table person (
        id varchar(12), -- handle/id/login
        name varchar(30),
        gang int4
    );

that joins another indexed table:

    create table gang (
        id serial,
        name varchar(30),
    primary key(id)
    );

is there any significant difference in the following two queries:

    select
        p.id as handle, p.name as person, g.name as gang
    from
        person p, gang g
    where
        PERSON.GANG = GANG.ID
    ;

    -- as opposed to:

    select
        p.id as handle, p.name as person, g.name as gang
    from
        person p, gang g
    where
        GANG.ID = PERSON.GANG
    ;

the only difference is GANG.ID=PERSON.GANG versus
PERSON.GANG=GANG.ID in the WHERE clause. does it matter?

--
It is always hazardous to ask "Why?" in science, but it is often
interesting to do so just the same.
        -- Isaac Asimov, 'The Genetic Code'

will@serensoft.com
http://newbieDoc.sourceforge.net/ -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!

Re: joins and indexes -- a=b or b=a?

From
Tom Lane
Date:
will trillich <will@serensoft.com> writes:
> the only difference is GANG.ID=PERSON.GANG versus
> PERSON.GANG=GANG.ID in the WHERE clause. does it matter?

No.  The query planner knows about commutativity ;-)

            regards, tom lane