Re: [sqlite] The "natural" order of the query results.

2018-09-16 Thread Darren Duncan
On 2018-09-16 1:29 AM, John Found wrote: Is there some relation between the indexes used in the query, the GROUP BY fields used and the order of the result rows, when no "ORDER BY" clause is used? I am asking, because I noticed, that on some queries, when I am using "ORDER BY" the query

Re: [sqlite] The "natural" order of the query results.

2018-09-16 Thread John Found
On Sun, 16 Sep 2018 10:59:31 -0400 Richard Hipp wrote: > On 9/16/18, John Found wrote: > > > > Is it means that in every query that uses GROUP BY and ORDER BY > > simultaneously, one of the operations will always be provided by using > > temporary b-tree? > > > > no. > > CREATE TABLE

Re: [sqlite] The "natural" order of the query results.

2018-09-16 Thread John Found
I know that the answer is "no", but in the below example, group by clause is meaningless, because (a,b) is primary key and there is no two rows with equal (a, b) that to be grouped. Please, comment my example from the first email in the thread. Is it possible to make this query to group by and

Re: [sqlite] The "natural" order of the query results.

2018-09-16 Thread Richard Hipp
On 9/16/18, John Found wrote: > > Is it means that in every query that uses GROUP BY and ORDER BY > simultaneously, one of the operations will always be provided by using > temporary b-tree? > no. CREATE TABLE t1(a,b,c, PRIMARY KEY(a,b)) WITHOUT ROWID; explain query plan SELECT a, b, sum(c)

Re: [sqlite] The "natural" order of the query results.

2018-09-16 Thread John Found
On Sun, 16 Sep 2018 13:30:55 +0100 Simon Slavin wrote: > On 16 Sep 2018, at 9:29am, John Found wrote: > > > Is there some relation between the indexes used in the query, the GROUP BY > > fields used > > and the order of the result rows, when no "ORDER BY" clause is used? > > When you ask

Re: [sqlite] The "natural" order of the query results.

2018-09-16 Thread Simon Slavin
On 16 Sep 2018, at 9:29am, John Found wrote: > Is there some relation between the indexes used in the query, the GROUP BY > fields used > and the order of the result rows, when no "ORDER BY" clause is used? When you ask for GROUP BY, SQLite internally does the same sort of thing as it does

Re: [sqlite] The "natural" order of the query results.

2018-09-16 Thread John Found
On Sun, 16 Sep 2018 19:27:40 +1000 Barry Smith wrote: > Without an order by, sqlite can return the rows in any order it pleases. > Likely whatever consumes the least resources. Although unlikely given your > indices, it might be possible - for instance if some future > micro-optimisation

Re: [sqlite] The "natural" order of the query results.

2018-09-16 Thread Barry Smith
Without an order by, sqlite can return the rows in any order it pleases. Likely whatever consumes the least resources. Although unlikely given your indices, it might be possible - for instance if some future micro-optimisation finds that it's quicker to read the index in reverse, then sqlite

[sqlite] The "natural" order of the query results.

2018-09-16 Thread John Found
Is there some relation between the indexes used in the query, the GROUP BY fields used and the order of the result rows, when no "ORDER BY" clause is used? I am asking, because I noticed, that on some queries, when I am using "ORDER BY" the query always use temporary b-tree for ordering, but