Hi guys!
I saw that the aggregate functions are not marked as contanst/deterministic.
Is there a reason for that?
I guess that a case like this:
SELECT count(*) FROM table
may be deterministic.
Is only deterministic as long as you do not INSERT or DELETE records.
For some tables this might be true for a very long time, for others table this can be a very, very, short time......
You can tell what value abs(-4) is by looking at it. That is a property
of being deterministic. You can't tell the value of count(*) without
knowing information about the database/table.
--
Richard Damon
_______________________________________________
sqlite-dev mailing list
sqlit...@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-dev
On 10 Mar 2019, at 11:06, Richard Damon <Ric...@Damon-Family.org> wrote:On 3/10/19 9:41 AM, Luuk wrote:And SQLite doesn't want to keep track of changes in the table
On 10-3-2019 06:47, Bernardino Ramos wrote:Hi galue uys!
I saw that the aggregate functions are not marked as
contanst/deterministic.
Is there a reason for that?
I guess that a case like this:
SELECT count(*) FROM table
may be deterministic.
Is only deterministic as long as you do not INSERT or DELETE records.
For some tables this might be true for a very long time, for others
table this can be a very, very, short time......
invalidating the constant for the aggregate function, and the mere fact
that it would have to indicates that the functions are NOT
deterministic, that being a function of just the parameter and not
anything external to it.
You can tell what value abs(-4) is by looking at it. That is a property
of being deterministic. You can't tell the value of count(*) without
knowing information about the database/table.
--
Richard Damon
_______________________________________________ sqlite-dev mailing list sqlit...@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-dev
A quick test shows what sqlite does do (i changed the query, but you already noted that there are better ones ;):
sqlite> drop table test;
sqlite> create table test (i int primary key);
sqlite> insert into test values (1);
sqlite> insert into test values (2);
sqlite> insert into test values (3);
sqlite> insert into test values (4);
sqlite>.eqp on
sqlite> select * from test where i in (select count(*) from
test) or i in (select count(*) from test);
QUERY PLAN
`--MULTI-INDEX OR
|--INDEX 1
| |--LIST SUBQUERY 1
| | `--SCAN TABLE test
| `--SEARCH TABLE test USING COVERING INDEX
sqlite_autoindex_test_1 (i=?)
`--INDEX 2
|--LIST SUBQUERY 2
| `--SCAN TABLE test
`--SEARCH TABLE test USING COVERING INDEX
sqlite_autoindex_test_1 (i=?)
i
4
sqlite>
It seems to search the table twice? or am i mis-interpreting
these results?
SELECT * FROM table1 WHERE (SELECT count(*) FROM table2) in (some_field1, some_field2)
(select count(*) from table2) is a constant and is only computed once ... however if you use it twice (as in your original query), then it will be computed twice.
The query planner does not know that they are the same subquery -- merely that they are subquery's returning a scalar constant result.
---
The fact that there's a Highway to Hell but only a Stairway to Heaven says a lot about anticipated traffic volume.
>-----Original Message-----
>From: sqlite-dev [mailto:sqlite-de...@mailinglists.sqlite.org]
>On Behalf Of Bernardo Ramos
>Sent: Sunday, 10 March, 2019 11:50
>To: sqlit...@mailinglists.sqlite.org
>Subject: Re: [sqlite-dev] Are aggregate functions not deterministic?
>
>
>
>
> On 10 Mar 2019, at 11:06, Richard Damon <Richard@Damon-
"indeed better ones, but this is what came to my mind now"
Are there people in this list who can write this query even better?
;)