Friday, March 9, 2012

How can same query be way slower on an identical database?

Hi,
I have SQL 2000 server on a P4 box. There are 8 - 10 databases total
and they are all backup/reporting purposes. So there are no other
users.
I have 2 identical databases with identical tables and identical
stored procedures. Only the data is different. Let me name them DB1
and DB2.
I execute the SP1 on DB1, which has more records than DB2, and it
gives me the results in 2 - 5 minutes.
I execute the SP2 (which is the exact copy of SP1) on DB2, which has
less records than the DB1, and it never gives me the result. After
hours it throws an error that is not specific.
I put indexes, tried to tune it etc. But no use. I still add some
records on both and run the query on Query Analyzer, and get results
for DB1 but not for DB2.
Why would it do this? Is this a database issue or the server issue you
think?
Thanks in advance.
- Denwell... they're not really identical if the rows are different... how have
you verified that schema is the same? Are you just 'sure' or have you used a
tool like DBCompare from redgate?
Also... have you looked at the estimate plans? Do they come back the same?
If not... you might have a statistics difference between the DB's... even if
schema is the same it's certainly possible that auto created stats could be
differernt between the db's...
hope this helps a bit,
--
Brian Moran
Principal Mentor
Solid Quality Learning
SQL Server MVP
http://www.solidqualitylearning.com
"DenoxiS" <google@.deniznet.com> wrote in message
news:d2478899.0402061716.7ffce2d2@.posting.google.com...
> Hi,
> I have SQL 2000 server on a P4 box. There are 8 - 10 databases total
> and they are all backup/reporting purposes. So there are no other
> users.
> I have 2 identical databases with identical tables and identical
> stored procedures. Only the data is different. Let me name them DB1
> and DB2.
> I execute the SP1 on DB1, which has more records than DB2, and it
> gives me the results in 2 - 5 minutes.
> I execute the SP2 (which is the exact copy of SP1) on DB2, which has
> less records than the DB1, and it never gives me the result. After
> hours it throws an error that is not specific.
> I put indexes, tried to tune it etc. But no use. I still add some
> records on both and run the query on Query Analyzer, and get results
> for DB1 but not for DB2.
> Why would it do this? Is this a database issue or the server issue you
> think?
> Thanks in advance.
> - Den|||If you are performing any kind of iterative calculation in the stored
procedure it could be that there is data on DB2 that is causing an infinite
loop. If the data on DB1 is "good" it would not have this problem. I have
run into this most often when handling date calculations.
"Brian Moran" <brian@.solidqualitylearning.com> wrote in message
news:u51B%23TS7DHA.3420@.TK2MSFTNGP11.phx.gbl...
> well... they're not really identical if the rows are different... how have
> you verified that schema is the same? Are you just 'sure' or have you used
a
> tool like DBCompare from redgate?
> Also... have you looked at the estimate plans? Do they come back the same?
> If not... you might have a statistics difference between the DB's... even
if
> schema is the same it's certainly possible that auto created stats could
be
> differernt between the db's...
> hope this helps a bit,
> --
> Brian Moran
> Principal Mentor
> Solid Quality Learning
> SQL Server MVP
> http://www.solidqualitylearning.com
>
> "DenoxiS" <google@.deniznet.com> wrote in message
> news:d2478899.0402061716.7ffce2d2@.posting.google.com...
> > Hi,
> >
> > I have SQL 2000 server on a P4 box. There are 8 - 10 databases total
> > and they are all backup/reporting purposes. So there are no other
> > users.
> >
> > I have 2 identical databases with identical tables and identical
> > stored procedures. Only the data is different. Let me name them DB1
> > and DB2.
> >
> > I execute the SP1 on DB1, which has more records than DB2, and it
> > gives me the results in 2 - 5 minutes.
> >
> > I execute the SP2 (which is the exact copy of SP1) on DB2, which has
> > less records than the DB1, and it never gives me the result. After
> > hours it throws an error that is not specific.
> >
> > I put indexes, tried to tune it etc. But no use. I still add some
> > records on both and run the query on Query Analyzer, and get results
> > for DB1 but not for DB2.
> >
> > Why would it do this? Is this a database issue or the server issue you
> > think?
> >
> > Thanks in advance.
> >
> > - Den
>|||Take a look at the selectivity of each set of tables. Is the data very similar ie is the distribution of data similar between the tables? Taking a better look at the generated query plans will provide you with the answers you are seeking.

No comments:

Post a Comment