SQLite Forum

big performance hit when querying 2 values in a single query instead of two
Login
i have the following schema filled with data:

<code>CREATE TABLE pro_comment(
	id         int,
	post_id    int,
	parent_id  int,
	content    text,
	created    int,
	up         int,
	down       int,
	confidence real,
	name       text,
	user_id    int,
	mark       int,
	item_id    int
);
CREATE INDEX pro_comment_id on pro_comment (id);
CREATE INDEX pro_comment_post_id__created on pro_comment (post_id, created);
CREATE INDEX pro_comment_name on pro_comment (name);</code>



and the following queries and their results:

<code>select 'max id:', max(id) from pro_comment;
max id:|52888040
Run Time: real 0.000 user 0.000000 sys 0.000082</code>

<code>select 'count distinct:', count(distinct id) from pro_comment;
count distinct:|46090875
Run Time: real 6.416 user 5.798688 sys 0.556307</code>

<code>select 'max id & count distinct:', max(id), count(distinct id) from pro_comment;
max id & count distinct:|52888040|46090875
Run Time: real 55.189 user 52.214868 sys 2.169683</code>



so when i select max(id) and count(distinct id) separately, it takes <7 seconds;
when i select them in the same query it takes 55 seconds which seems odd to me.

i am not certain if this is a bug or already explained somewhere. 
if it is not a bug, i'd appreciate if someone could link me some explanation for this behavior, so i can dodge it in the future.

observerd on debian, sqlite3 version:
3.36.0 2021-06-18 18:36:39 5c9a6c06871cb9fe42814af9c039eb6da5427a6ec28f187af7ebfb62eafaalt1