Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.databases.ms-sqlserver    |    Notorious Rube Goldberg contraption    |    19,505 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 17,743 of 19,505    |
|    Gert-Jan Strik to bill    |
|    Re: Using @variable in WHERE clause when    |
|    29 Jan 10 10:36:34    |
      bfa7d031       From: sorrytoomuchspamalready@xs4all.nl              Bill,              When the view is very complex, sometimes the query optimizer chooses to       not expand the view, causing it to handle the view like a derived table.       For example, this could happen when you join two (complex) views in a       query.              In this case, it obviously shouldn't do that.              You could try to disable parallellism for the query. That might pursuade       the optimizer to change it's plan. Add "OPTION (maxdop 1)" to do this.              --       Gert-Jan                     bill wrote:       >       > I much prefer examples and apologize that this question doesn't       > have one.       >       > I unfortunately can't post CREATE TABLE statements       > for this problem becuase the issue doesn't show up until       > you get lots of rows in the tables, and the tables themselves       > are quite convoluted in structure (commercial system, I can't       > do anything about that).       >       > My query joins six tables, the largest of which       > (call it Driver_Table) is about 5.4 million rows.       > This is the "driving" table, because the other tables       > are OUTER joined to the driver, by which       > I mean that the rows in Driver_Table are preserved.       >       > Driver_Table has a two part composite primary key.       > The first column in this key is called "invoice_no".       > I limit the result set with a WHERE clause       > that specifies the invoice_no.       >       > A typical query returns 30 to 100 rows based on the       > WHERE clause, so invoice_no is nice and       > selective.       >       > I made the query into a view, and that's where things       > got weird:       >       > 1.       > SELECT * FROM |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca