J
Joseph Geretz
I came across a performance problem recently in my application. I'm not
using Access, the DB is Interbase, but I tracked down the problem to a
specific query. This may not be a vendor specific issue at all and if not,
perhaps you can help with this.
I have a Table, let's call it T1 which has a one to many relationship with a
secondary table, let's call it T2. Within the context of my application, the
join between these two is so common that I've created a VIEW for it:
SELECT T1.T1A,
T1.T1B,
T2.T2A,
T2.T2B
FROM T1 LEFT JOIN T2 ...
Now, at various points in my application I'm selecting * from this VIEW.
Sometimes I'm selecting WHERE T1B = 'blah'. This yields excellent
performance.
Other times though, I'm selecting WHERE T2B = 'yada'. In this case,
performance is abysmal. Now this is interesting. The field for my filter
criteria is from the right hand table of a LEFT JOIN. Now LEFT JOIN
specifies 'All the records from the table on the left and any matching
records from table on the right'. This being the case, it seems that if the
WHERE clause relates to the table on the right, ALL records from the table
T1 are gathered. Then ALL records from the table on the right are gathered.
Then from the resulting recordset, rows which don't fit the WHERE criteria
are eliminated. This explains the abysmal performance.
(But I'd have thought the plan optimizer would see the WHERE criteria
pertains to the table on the right, and use that table as the launching
point for execution.)
So I switched T1 and T2 around and placed T2 on the left. This immediately
improved performance in the problem area, but had the effect of slowing down
the other areas of the application which were previously performing
beautifully.
Ultimately, the only way I could see to address this is by creating two
VIEWS, one with T1 on the left, and one with T2 on the left, and taking care
to select from the appropriate VIEW depending on the WHERE filtering
criteria. Is there a better way of doing this with only one VIEW?
(BTW, I did try an INNER JOIN, but this resulted in mediocre performance in
all areas.)
Have you ever encountered this type of scenario? If so, how did you address
this?
Thanks for any advice which you can provide.
- Joe Geretz -
using Access, the DB is Interbase, but I tracked down the problem to a
specific query. This may not be a vendor specific issue at all and if not,
perhaps you can help with this.
I have a Table, let's call it T1 which has a one to many relationship with a
secondary table, let's call it T2. Within the context of my application, the
join between these two is so common that I've created a VIEW for it:
SELECT T1.T1A,
T1.T1B,
T2.T2A,
T2.T2B
FROM T1 LEFT JOIN T2 ...
Now, at various points in my application I'm selecting * from this VIEW.
Sometimes I'm selecting WHERE T1B = 'blah'. This yields excellent
performance.
Other times though, I'm selecting WHERE T2B = 'yada'. In this case,
performance is abysmal. Now this is interesting. The field for my filter
criteria is from the right hand table of a LEFT JOIN. Now LEFT JOIN
specifies 'All the records from the table on the left and any matching
records from table on the right'. This being the case, it seems that if the
WHERE clause relates to the table on the right, ALL records from the table
T1 are gathered. Then ALL records from the table on the right are gathered.
Then from the resulting recordset, rows which don't fit the WHERE criteria
are eliminated. This explains the abysmal performance.
(But I'd have thought the plan optimizer would see the WHERE criteria
pertains to the table on the right, and use that table as the launching
point for execution.)
So I switched T1 and T2 around and placed T2 on the left. This immediately
improved performance in the problem area, but had the effect of slowing down
the other areas of the application which were previously performing
beautifully.
Ultimately, the only way I could see to address this is by creating two
VIEWS, one with T1 on the left, and one with T2 on the left, and taking care
to select from the appropriate VIEW depending on the WHERE filtering
criteria. Is there a better way of doing this with only one VIEW?
(BTW, I did try an INNER JOIN, but this resulted in mediocre performance in
all areas.)
Have you ever encountered this type of scenario? If so, how did you address
this?
Thanks for any advice which you can provide.
- Joe Geretz -