Re: [sqlite] Query plan of MAX (id) versus MAX (id) + 1 in a range

2010-02-22 Thread ArtemGr
Simon Slavin slav...@... writes: Just out of interest, and I know that theoretically this is not an optimal statement, but have you compared this with the results of putting the '+1' in the brackets ? Thanks for the pointer, Simon. Looking back to my analizys, I see that it was wrong. SELECT

Re: [sqlite] Query plan of MAX (id) versus MAX (id) + 1 in a range

2010-02-22 Thread Pavel Ivanov
Obvioulsy, SQLite already have a special case optimization for MAX (id), but optimization breaks with MAX (id) + 1, making it impractical for use in INSERT SELECT. Even not all kind of MAX(id) queries are optimized: http://www.sqlite.org/optoverview.html#minmax Pavel On Mon, Feb 22, 2010 at

Re: [sqlite] Query plan of MAX (id) versus MAX (id) + 1 in a range

2010-02-22 Thread Jim Morris
Did you try something like: SELECT id + 1 FROM foo WHERE id= 100 AND id 200 and id = MAX (id); On 02/22/2010 7:02 AM, ArtemGr wrote: Simon Slavinslav...@... writes: Just out of interest, and I know that theoretically this is not an optimal statement, but have you compared this with

Re: [sqlite] Query plan of MAX (id) versus MAX (id) + 1 in a range

2010-02-22 Thread Pavel Ivanov
Did you try something like: SELECT  id + 1 FROM foo WHERE id= 100 AND id  200 and id = MAX (id); Probably you meant SELECT  id + 1 FROM foo WHERE id= 100 AND id  200 ORDER BY id DESC LIMIT 1; Otherwise it's incorrect SQL. Pavel On Mon, Feb 22, 2010 at 5:27 PM, Jim Morris

[sqlite] Query plan of MAX (id) versus MAX (id) + 1 in a range

2010-02-20 Thread Artem Kozarezov
Let's create and populate a test table: sqlite CREATE TABLE foo (id INTEGER PRIMARY KEY NOT NULL); sqlite INSERT INTO foo VALUES (1); sqlite INSERT INTO foo VALUES (100); sqlite INSERT INTO foo VALUES (200); sqlite INSERT INTO foo SELECT MAX (id) + 1 FROM foo WHERE id = 100 AND id 200; sqlite

Re: [sqlite] Query plan of MAX (id) versus MAX (id) + 1 in a range

2010-02-20 Thread Simon Slavin
On 20 Feb 2010, at 1:14pm, Artem Kozarezov wrote: Also, it would be nice and intuitive if the MAX (id) and MAX (id) + 1 worked optimally within a range! Just out of interest, and I know that theoretically this is not an optimal statement, but have you compared this with the results of