Repository navigation
Count distinct rows in COUNT(DISTINCT *) to close #2758 - #2994
Conversation
|
Thank you for this @mateuscmtropical Going from "always 1" to a real count is the right direction, but comparing rows with CREATE TABLE t (x INT, y INT);
INSERT INTO t (x, y) VALUES (1, 2);
INSERT INTO t (y, x) VALUES (2, 1);
SELECT COUNT(DISTINCT *) AS n FROM t; -- gives 2, should be 1The same happens in three other cases.
Please build the key only from the row of the named table, or from all tables when no table is named. Sort the keys, and treat NULL and undefined the same. Then add a test for each case above. A general note, as you have many PRs open. We value quality over quantity. One complete PR helps the project more than several that need another round of review. Before you open a PR, please test the edge cases around your change, not only the case in the issue. Check NULL against undefined, column order, JOINs, and values such as Date and BigInt. Then your work gets merged faster, and we spend less time on reviews. |
|
Thanks for the cases. I changed the key in two places:
Noted on quality over quantity. I'll test these edge cases before opening the next ones. |
Closes #2758
COUNT(DISTINCT *)returned 1 for any number of rows. The distinct check used the value of the column*, which isundefinedfor every row, so after the first row nothing was counted.src/15utility.jsaddsalasql.utils.distinctRowKey, the key of a row. It sorts the columns and leaves out NULL and undefined values, so the column order and an omitted column do not matter. A number and a BigInt are keyed by their digits and a Date by its time. NULL in anINTcolumn is stored asNaN, soNaNcounts as NULL too.src/423groupby.jsuses that key for aDISTINCTaggregate over*.COUNT(DISTINCT t1.*)keys the row oft1, andCOUNT(DISTINCT *)the row of all tables. OtherDISTINCTaggregates keep their key.COUNT(DISTINCT *)stays accepted, as the issue asks.test/test2758.jscovers a table with a repeated row and a row with NULL,GROUP BY, parameter data,COUNT(DISTINCT x)as before, rows inserted with the columns in another order, an explicit NULL next to an omitted column,t4.*,t5.*and*in a JOIN, and BigInt and Date values. The tests fail ondevelopand pass with the change.yarn test-onlygives 2558 pass. The only failures are the 5Test 418cases that load data from the internet, and they fail the same way ondevelopin my environment.