Tomáš,
in general, I think this should be possible. Why is is not in your case is hard to says given the little information.
Could you possibly share (some of) the following information:
- hardware characteristics: CPU (type, #cores, clockspeed), amount of RAM, type of I/O system (single HDD, HDD RAID, SSD, NVMe, ...)
Further, to understand where time goes, one would need to know the query plan MonetDB generates and uses, and profile the query.
Could you produce the PLAN (logical plan), EXPLAIN (physical plan), and TRACE (execution time profiling) of your query (see https://www.monetdb.org/Documentation/Manuals/SQLreference/Runtime for details), and share them (if not here then via email)?
Could you try to run on a non-Windows (preferable Linux) system? We don't have the best experiences regarding performance with Windows ...
Thanks!
Stefan
ps:
You can also try to revise your query slightly as follows, and see whether this helps:
SELECT COUNT(DISTINCT id) FROM tbl WHERE
a1=22
AND xb>=143455
AND yb>=90911
AND xa<=143615
AND ya<=91007
AND a2 between 2 and 4
AND a3 between 0 and 4
AND a4 between 0 and 2
AND a5 IN (-1, 1, 2, 3, 4, 5, 6, 7)
AND a6 IN (-1, 11, 12, 13, 14)
;
or even
SELECT COUNT(DISTINCT id) FROM tbl WHERE
a1=22
AND xb>=143455
AND yb>=90911
AND xa<=143615
AND ya<=91007
AND a2 between 2 and 4
AND a3 between 0 and 4
AND a4 between 0 and 2
AND (a5 = -1 or a5 between 1 and 7)
AND (a6 = -1 or a6 between 11 and 14)
;
Also, could you possibly check and share the following statistics of your data:
select
count(*),
count(id), count(distinct id),
count(xa), count(distinct xa),
count(xb), count(distinct xb),
count(ya), count(distinct ya),
count(yb), count(distinct yb),
count(a1), count(distinct a1),
count(a2), count(distinct a2),
count(a3), count(distinct a3),
count(a4), count(distinct a4),
count(a5), count(distinct a5),
count(a6), count(distinct a6),
count(a7), count(distinct a7),
count(a8), count(distinct a8),
count(a9), count(distinct a9)
from tbl
;
select count(*) from tbl where a1=22;
select count(*) from tbl where xb>=143455;
select count(*) from tbl where yb>=90911;
select count(*) from tbl where xa<=143615;
select count(*) from tbl where ya<=91007;
select count(*) from tbl where a2 IN (2, 3, 4);
select count(*) from tbl where a3 IN (0, 1, 2, 3, 4);
select count(*) from tbl where a4 IN (0, 1, 2);
select count(*) from tbl where a5 IN (-1, 1, 2, 3, 4, 5, 6, 7);
select count(*) from tbl where a6 IN (-1, 11, 12, 13, 14);