Thread: Benchmark two separate SELECTs versus one LEFT JOIN

Benchmark two separate SELECTs versus one LEFT JOIN

From
Miles Keaton
Date:
Has anyone seen a benchmark on the speed difference between:

SELECT * FROM item WHERE id=123;
and
SELECT * FROM vendor WHERE id=515;

versus:

SELECT * FROM item LEFT JOIN vendor ON item.vendor_id=vendor.id WHERE
item.id=123;



I only have a laptop here so I can't really benchmark properly.
I'm hoping maybe someone else has, or just knows which would be faster
under high traffic/quantity.

Thanks!

Re: Benchmark two separate SELECTs versus one LEFT JOIN

From
Josh Berkus
Date:
Miles,

> I only have a laptop here so I can't really benchmark properly.
> I'm hoping maybe someone else has, or just knows which would be faster
> under high traffic/quantity.

Well, it's really a difference between round-trip time vs. the time required
to compute the join.   If your database is setup correctly, the 2nd should be
faster.

However, it should be very easy to test ....

--
Josh Berkus
Aglio Database Solutions
San Francisco