Thursday, May 29, 2008

Cartesian Merge

When trying to ensure a pair of fields match another pair of fields, do not use bars as this creates a Cartesian Merge which can significantly slow down your program. Use commas to separate the fields as shown in the 2nd example.

WRONG CODE:
SELECT field1, field2
FROM table
WHERE field1||field2 IN /* NO */
(SELECT field1||fieldS2 /* NO */
FROM table
WHERE some conditions);
CORRECT CODE:
SELECT field1, field2
FROM table
WHERE (field1,field2) IN /* YES */
(SELECT field1,fieldS2 /* YES */
FROM table
WHERE some conditions);

No comments:

Post a Comment