[MCOL-3839] Count as a window function doesn't work with NULLs Created: 2020-02-25  Updated: 2020-11-12  Resolved: 2020-05-06

Status: Closed
Project: MariaDB ColumnStore
Component/s: None
Affects Version/s: 1.2.5
Fix Version/s: 1.4.4, 1.5.1

Type: Bug Priority: Major
Reporter: Patrick Safarov Assignee: Daniel Lee (Inactive)
Resolution: Fixed Votes: 0
Labels: None

Sprint: 2020-4, 2020-5, 2020-6, 2020-7
Epic/Theme: 1.4_regressions

 Description   

MariaDB [smtp_email_validator]> select count(null) over () from logs where timestamp > now() - interval 1 hour; 
ERROR 1815 (HY000): Internal error: InetStreamSocket::readToMagic: Remote is closed
MariaDB [smtp_email_validator]> show warnings\G
*************************** 1. row ***************************
  Level: Error
   Code: 1815
Message: Internal error: InetStreamSocket::readToMagic: Remote is closed
*************************** 2. row ***************************
  Level: Error
   Code: 1030
Message: Got error 1815 "Unknown error 1815" from storage engine InfiniDB
*************************** 3. row ***************************
  Level: Error
   Code: 1815
Message: Internal error: /data/buildbot/bb-worker/centos7/mariadb-columnstore-engine/dbcon/execplan/clientrotator.cpp: Could not get a connection to a ExeMgr
3 rows in set (0.000 sec)

If we use an expression as a `count ` argument, it counts all rows including the ones containing NULLs



 Comments   
Comment by David Hall (Inactive) [ 2020-03-02 ]

One may be tempted to ask why anyone would write count(NULL). Automated systems do.

Comment by David Hall (Inactive) [ 2020-04-24 ]

Looking at colIn == -1 to check for NULL has the incorrect assumption that the -1 is caused by a NULL parameter. What is actually happening is that because the parameter is a constant, the field index is -1. Any constant will do this.
This solution results in any constant parameter being treated as NULL, which is incorrect.
A more correct solution is to look at the value of fConstantColumns[0] for the constant value. Unfortunately, the value inserted here for NULL is 0 (incorrect). Perhaps adding a line in ConstantColumn.cpp after if (fType == ConstantColumn::NULLDATA) to push the actual NULL value in would work.

Comment by Jose Rojas (Inactive) [ 2020-04-24 ]

I have updated change to work for other constants as well as NULLs.

Comment by Daniel Lee (Inactive) [ 2020-05-06 ]

Build verified: 1.4.4-1m 1.5.0-1 source

1.4.4-1

/root/ColumnStore/buildColumnstoreFromGithubSource/server
commit d8ff39957275afc7a870487631cd3b3be5eb8818
Author: Rasmus Johansson <razze@iki.fi>
Date: Mon May 4 10:10:07 2020 +0000

MDEV-22273 jUnit patch: xml test result differs from MTR output in case if retry

/root/ColumnStore/buildColumnstoreFromGithubSource/server/engine
commit 4c275557633edb60905faa500990d55a6834951d
Merge: aa054a9 47f2933
Author: David.Hall <david.hall@mariadb.com>
Date: Tue May 5 12:34:03 2020 -0500

Merge pull request #1179 from pleblanc1976/update-libs3-ref

Updated the s3 lib.

1.5.0-1

/root/ColumnStore/buildColumnstoreFromGithubSource/server
commit 43b7e5d29a5480214cee8317a4625b749ccffbaf
Author: Rasmus Johansson <razze@iki.fi>
Date: Mon May 4 10:10:07 2020 +0000

MDEV-22273 jUnit patch: xml test result differs from MTR output in case if retry

/root/ColumnStore/buildColumnstoreFromGithubSource/server/engine
commit 368c4fac059d5cf4f1596e56ea7b1e729e29ec49
Merge: 15a9efa 4bc408c
Author: David.Hall <david.hall@mariadb.com>

Date: Tue May 5 12:35:14 2020 -0500

Merge pull request #1178 from pleblanc1976/update-libs3-ref-1.5

Updated s3 lib ref

Reproduced the issue in 1.2.5-1

MariaDB [mytest]> select count(null) over () from orders where o_orderdate > '1997-05-17' - interval 1 hour;
ERROR 1815 (HY000): Internal error: InetStreamSocket::readToMagic: Remote is closed

MariaDB [mytest]> select count(null) over () from orders where o_orderdate > '1998-08-02' - interval 1 hour;
---------------------

count(null) over ()

---------------------

0

.
.
.

0
0

---------------------
581 rows in set (0.070 sec)

MariaDB [mytest]> select count from orders where o_orderdate = '1998-08-02';
----------

count

----------

581

----------
1 row in set (0.057 sec)

Generated at Thu Feb 08 02:45:49 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.