Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent results in count queries #20

Open
eclbg opened this issue Jul 9, 2019 · 1 comment
Open

Inconsistent results in count queries #20

eclbg opened this issue Jul 9, 2019 · 1 comment

Comments

@eclbg
Copy link

eclbg commented Jul 9, 2019

The following two queries yield different results while I understand they should be equivalent. The second one yields the correct result.

SELECT COUNT(1) FROM (SELECT DISTINCT report_id FROM clickhouse_reportusages) t;
 count
-------
  2000
SELECT COUNT(DISTINCT report_id) FROM clickhouse_reportusages;
 count
-------
  2956

Their respective plans are:

EXPLAIN VERBOSE SELECT COUNT(1) FROM (SELECT DISTINCT report_id FROM clickhouse_reportusages) t;
                                            QUERY PLAN
--------------------------------------------------------------------------------------------------
 Aggregate  (cost=1.51..1.52 rows=1 width=8)
   Output: count(1)
   ->  Unique  (cost=1.00..1.50 rows=1 width=4)
         Output: clickhouse_reportusages.report_id
         ->  Foreign Scan on public.clickhouse_reportusages  (cost=1.00..-1.00 rows=1000 width=4)
               Output: clickhouse_reportusages.report_id
               Remote SQL: SELECT report_id FROM "default".reportusages ORDER BY report_id ASC
(7 rows)
EXPLAIN VERBOSE SELECT COUNT(DISTINCT report_id) FROM clickhouse_reportusages;
                                 QUERY PLAN
----------------------------------------------------------------------------
 Foreign Scan  (cost=1.00..-1.00 rows=1000 width=8)
   Output: (count(DISTINCT report_id))
   Relations: Aggregate on (clickhouse_reportusages)
   Remote SQL: SELECT count(DISTINCT report_id) FROM "default".reportusages
(4 rows)
@alanrigele
Copy link

Similar experiences have been seen with the latest code.

select count(node) from calculated_kpis
provides different results for each query even though the underlying data is not changed.

select count(*) from (select node from calculated_kpis) a
provides the correct result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants