I am looking for an expert opinion on the speed difference between fetching
related data from 2 tables with a join and fetching them in to single
selects.

The scenario is kind of the following:

SELECT a , b, c FROM table1 WHERE a='x'; # gets b='y'
SELECT b, d , e, f FROM table2 WHERE b='y';

instead 

SELECT a , b, c, d , e, f FROM table1, table2
WHERE a='x' AND table1.b = table2.b;

Background: I wrote a little Perl module that automatically instantiates a
object for each table in the database connected to and each table object
allows you to access any record in that table or create a new one. So the
above SQL looks like:
    
    my $DB = DB->new($config);
    my $record_a_b_c = $DB->table1->new(primary_key_value);
    my $field_b_value = $record_a_b_c->fieldname;
    my $record_b_d_e_f = $DB->table2->new($field_b_value);

In this scenario it very easy to retrieve related from several tables
without doing a join, but I am not sure how hard the performance hit
actually is, since MySQL would have to look up the first select before it
can do the join on the second table.

Thanks for your input.

/h

<mysql, query, table>


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to