Joerg Bruehe <[EMAIL PROTECTED]> wrote on 08/05/2005 02:08:35 PM: > Hi David, all! > > David Sparks wrote: > > I have a query that is taking days to complete (not good). If I change > > the query so that it selects less rows it runs fast. > > I fear I have no decisive hint for this (sorry), but still ... > > > > > [[...]] > > > > mysql> select count(*) from msgs where message_id > 1120000000 and > > message_id < 1120000111; > > [[...]] > > Have you considered using BETWEEN? > IMNSHO, this will both improve the readability of your SQL statement > and at the same time help the optimizer (and avoid typing errors!). > > Yes, logically it is equivalent, but in C you also write > len++; > or > len+= 1; > and not > len= len + 1; > > Regards, > Jörg > > -- > Joerg Bruehe, Senior Production Engineer > MySQL AB, www.mysql.com > Office: (+49 30) 417 01 487 > Actually, no, he cannot substitute BETWEEN as BETWEEN is _inclusive_ of the boundary conditions (a closed interval). In this case he does not wasnt values equal to his boundaries (an open interval)
WHERE X BETWEEN A and B Is equivalent to WHERE X>=A and X<=B His original WHERE clause was comparing X>A and X<B (no equality). The two are close but not the same. Shawn Green Database Administrator Unimin Corporation - Spruce Pine