I think it is only a problem if you are having performance issues. In
most of my programs there is usually a much more efficient way of doing
things, but if it takes 5ms or 1ms it doesn't really make any difference
compared to everything else. I would only start optimising if you are
having issues. If you've got an index on description in the container
field that would make the lookup very quick.
Ryan
On 7/03/2012 3:29 PM, Cecil Westerhof wrote:
I am using the following SQL code:
CREATE TABLE container (
containerID UUID PRIMARY KEY,
parentContainerId UUID,
description VARCHAR(50) NOT NULL,
FOREIGN KEY(parentContainerID) REFERENCES (containerID)
);
INSERT INTO container (containerID, description) VALUES
(random_UUID(), 'vriezer');
INSERT INTO container (
containerID,
parentContainerID,
description
) VALUES (
random_UUID(),
SELECT containerID FROM container WHERE description = 'vriezer',
'bovenste lade'
);
INSERT INTO container (
containerID,
parentContainerID,
description
) VALUES (
random_UUID(),
SELECT containerID FROM container WHERE description = 'vriezer',
'middelste lade'
);
INSERT INTO container (
containerID,
parentContainerID,
description
) VALUES (
random_UUID(),
SELECT containerID FROM container WHERE description = 'vriezer',
'onderste lade'
);
Now the containerID for 'vriezer' is fetched three times. That sounds
inefficient to me. Can that be done more efficient in SQL? (In a
program it would not be to difficult, but I would like a 'pure' SQL
solution.) Or is it not a real problem because of caching?
--
You received this message because you are subscribed to the Google Groups "H2
Database" 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/h2-database?hl=en.