[MDEV-20280] PERCENTILE_DISC() rejects temporal and string input Created: 2019-08-07  Updated: 2022-12-23  Resolved: 2020-06-01

Status: Closed
Project: MariaDB Server
Component/s: Data types, Optimizer - Window functions
Affects Version/s: 10.3, 10.4, 10.5
Fix Version/s: 10.5.4

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Problem/Incident
causes MDEV-30292 Server crashes in Static_binary_strin... Confirmed
Relates
relates to MDEV-20272 PERCENTILE_DISC() crashes on a tempor... Closed
relates to MDEV-21392 Cleanup redundant overriding in Item_... Closed
relates to MDEV-22764 Crash with a stored aggregate functio... Closed

 Description   

PERCENTILE_DISC() now return an error on temporal and string input:

CREATE OR REPLACE TABLE t1 (name CHAR(30), star_rating TIME);
INSERT INTO t1 VALUES ('Lord of the Ladybirds', '00:00:05');
INSERT INTO t1 VALUES ('Lord of the Ladybirds', '00:00:03');
INSERT INTO t1 VALUES ('Lady of the Flies', '00:00:01');
INSERT INTO t1 VALUES ('Lady of the Flies', '00:00:02');
INSERT INTO t1 VALUES ('Lady of the Flies', '00:00:05');
SELECT name, PERCENTILE_DISC(0.5)
  WITHIN GROUP (ORDER BY star_rating)
  OVER (PARTITION BY name) AS pc FROM t1;

ERROR 4101 (HY000): Numeric datatype is required for percentile_disc function

It should be extended to support all string and temporal data types.

Note, PERCENTILE_DISC() previously crashed on temporal input. The patch for MDEV-20272 fixed the crash and made it return an error instead. Allowing temporal and string types in PERCENTILE_DISC() needs some refactoring, which was not desirable in 10.3.

Refactoring needed:
Item_sum_percentile_disc currently recursively derives from Item_sum_num, which cannot return string/temporal values by design.
In order to support string/temporal data types in PERCENTILE_DISC(), Item_sum_percentile_disc should be moved to the Item_sum_hybrid
branch in the hierarchy.

It's not desirable to do such refactoring in 10.3 or 10.4.


Generated at Thu Feb 08 08:58:15 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.