On 03/05/2011, at 8:59 AM, Ian MacLeod wrote:
On May 2, 2:47 pm, Clifford Heath <[email protected]> wrote:
Please consider using
an RDBMS with a proper optimiser. Postgres is a good free option.
I'd love to for future projects, but switching mid-stream isn't
something I'd like to entertain.
Of course... but it's still something I need to keep putting out
there :).
Now, say I have some data populated and I want to grab all the
rights
associated with a left object (let's just use the first one for
ease):
Left.first.rights
For one, the "INNER JOIN lefts ON joins.left_id = lefts.id" is
completely unnecessary.
No, it isn't. You've asked DataMapper for the first Left, and all
its Rights, and that's exactly what it's giving you. It has no way
to know that you aren't using the Left it loads for you.
Sure it does - DataMapper is generating the query without any
references to the lefts table in the SELECT clause.
Hmmm. It fetches Left.first in a previous query, relevant if you had
said:
(l = Left.first).rights
However in the subsequent query for the Rights, if you had chosen
not to enforce the join.left_id foreign key, then you might have a
record which refers to no Left record (
I guess this guards against cases where the left row is missing but
the join still exists - but the FK constraints wouldn't allow that,
regardless.
*If* they're being enforced; I don't think DM knows that. Even
though it just fetched the Left record, perhaps you aren't in a
transaction and it got deleted? So it's good practise to include
Left table in this join. A decent DBMS optimiser will know
whether it can safely drop the reference anyhow... not that I'd
expect such clever behaviour from MySQL.
Clifford Heath.
--
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en.