mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-18 03:23:37 +08:00
Fix group handling in time_bucket_gapfill
When time_bucket_gapfill is used with multiple groups but the query returned no rows we can not generate any rows in the gapfill node.
This commit is contained in:
parent
3a81559453
commit
e6c68f89b9
@ -11,6 +11,7 @@ accidentally triggering the load of a previous DB version.**
|
|||||||
**Thanks**
|
**Thanks**
|
||||||
|
|
||||||
* @jamessewell for reporting and helping debug a segfault in last()
|
* @jamessewell for reporting and helping debug a segfault in last()
|
||||||
|
* @piscopoc for reporting a segfault in time_bucket_gapfill
|
||||||
|
|
||||||
## 1.2.0 (2019-01-29)
|
## 1.2.0 (2019-01-29)
|
||||||
|
|
||||||
|
@ -401,7 +401,17 @@ gapfill_exec(CustomScanState *node)
|
|||||||
gapfill_state_set_next(state, slot);
|
gapfill_state_set_next(state, slot);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
state->state = FETCHED_LAST;
|
{
|
||||||
|
/*
|
||||||
|
* if GROUP BY has non time_bucket_gapfill columns but the
|
||||||
|
* query has not initialized the groups there is nothing we
|
||||||
|
* can do here
|
||||||
|
*/
|
||||||
|
if (state->multigroup && !state->groups_initialized)
|
||||||
|
return NULL;
|
||||||
|
else
|
||||||
|
state->state = FETCHED_LAST;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return any subplan tuples before gapfill_start */
|
/* return any subplan tuples before gapfill_start */
|
||||||
|
@ -237,6 +237,22 @@ GROUP BY 1 ORDER BY 1;
|
|||||||
4 |
|
4 |
|
||||||
(5 rows)
|
(5 rows)
|
||||||
|
|
||||||
|
-- test gap fill without rows in resultset
|
||||||
|
SELECT
|
||||||
|
time_bucket_gapfill(1,time,0,5),
|
||||||
|
min(time)
|
||||||
|
FROM (VALUES (1),(2),(3)) v(time)
|
||||||
|
WHERE false
|
||||||
|
GROUP BY 1 ORDER BY 1;
|
||||||
|
time_bucket_gapfill | min
|
||||||
|
---------------------+-----
|
||||||
|
0 |
|
||||||
|
1 |
|
||||||
|
2 |
|
||||||
|
3 |
|
||||||
|
4 |
|
||||||
|
(5 rows)
|
||||||
|
|
||||||
-- test coalesce
|
-- test coalesce
|
||||||
SELECT
|
SELECT
|
||||||
time_bucket_gapfill(1,time,0,5),
|
time_bucket_gapfill(1,time,0,5),
|
||||||
@ -371,6 +387,18 @@ GROUP BY 1,id ORDER BY 2,1;
|
|||||||
4 | 2 |
|
4 | 2 |
|
||||||
(10 rows)
|
(10 rows)
|
||||||
|
|
||||||
|
-- test grouping by non-time columns with no rows in resultset
|
||||||
|
SELECT
|
||||||
|
time_bucket_gapfill(1,time,0,5) as time,
|
||||||
|
id,
|
||||||
|
min(value) as m
|
||||||
|
FROM (VALUES (1,1,1),(2,2,2)) v(time,id,value)
|
||||||
|
WHERE false
|
||||||
|
GROUP BY 1,id ORDER BY 2,1;
|
||||||
|
time | id | m
|
||||||
|
------+----+---
|
||||||
|
(0 rows)
|
||||||
|
|
||||||
-- test duplicate columns in GROUP BY
|
-- test duplicate columns in GROUP BY
|
||||||
SELECT
|
SELECT
|
||||||
time_bucket_gapfill(1,time,0,5) as time,
|
time_bucket_gapfill(1,time,0,5) as time,
|
||||||
@ -434,6 +462,18 @@ GROUP BY 1,color ORDER BY 2,1;
|
|||||||
4 | red |
|
4 | red |
|
||||||
(10 rows)
|
(10 rows)
|
||||||
|
|
||||||
|
-- test grouping by non-time columns with text columns with no rows in resultset
|
||||||
|
SELECT
|
||||||
|
time_bucket_gapfill(1,time,0,5) as time,
|
||||||
|
color,
|
||||||
|
min(value) as m
|
||||||
|
FROM (VALUES (1,'blue',1),(2,'red',2)) v(time,color,value)
|
||||||
|
WHERE false
|
||||||
|
GROUP BY 1,color ORDER BY 2,1;
|
||||||
|
time | color | m
|
||||||
|
------+-------+---
|
||||||
|
(0 rows)
|
||||||
|
|
||||||
-- test insert into SELECT
|
-- test insert into SELECT
|
||||||
CREATE TABLE insert_test(id INT);
|
CREATE TABLE insert_test(id INT);
|
||||||
INSERT INTO insert_test SELECT time_bucket_gapfill(1,time,1,5) FROM (VALUES (1),(2)) v(time) GROUP BY 1 ORDER BY 1;
|
INSERT INTO insert_test SELECT time_bucket_gapfill(1,time,1,5) FROM (VALUES (1),(2)) v(time) GROUP BY 1 ORDER BY 1;
|
||||||
|
@ -166,6 +166,14 @@ SELECT
|
|||||||
FROM (VALUES (1),(2),(3)) v(time)
|
FROM (VALUES (1),(2),(3)) v(time)
|
||||||
GROUP BY 1 ORDER BY 1;
|
GROUP BY 1 ORDER BY 1;
|
||||||
|
|
||||||
|
-- test gap fill without rows in resultset
|
||||||
|
SELECT
|
||||||
|
time_bucket_gapfill(1,time,0,5),
|
||||||
|
min(time)
|
||||||
|
FROM (VALUES (1),(2),(3)) v(time)
|
||||||
|
WHERE false
|
||||||
|
GROUP BY 1 ORDER BY 1;
|
||||||
|
|
||||||
-- test coalesce
|
-- test coalesce
|
||||||
SELECT
|
SELECT
|
||||||
time_bucket_gapfill(1,time,0,5),
|
time_bucket_gapfill(1,time,0,5),
|
||||||
@ -230,6 +238,15 @@ SELECT
|
|||||||
FROM (VALUES (1,1,1),(2,2,2)) v(time,id,value)
|
FROM (VALUES (1,1,1),(2,2,2)) v(time,id,value)
|
||||||
GROUP BY 1,id ORDER BY 2,1;
|
GROUP BY 1,id ORDER BY 2,1;
|
||||||
|
|
||||||
|
-- test grouping by non-time columns with no rows in resultset
|
||||||
|
SELECT
|
||||||
|
time_bucket_gapfill(1,time,0,5) as time,
|
||||||
|
id,
|
||||||
|
min(value) as m
|
||||||
|
FROM (VALUES (1,1,1),(2,2,2)) v(time,id,value)
|
||||||
|
WHERE false
|
||||||
|
GROUP BY 1,id ORDER BY 2,1;
|
||||||
|
|
||||||
-- test duplicate columns in GROUP BY
|
-- test duplicate columns in GROUP BY
|
||||||
SELECT
|
SELECT
|
||||||
time_bucket_gapfill(1,time,0,5) as time,
|
time_bucket_gapfill(1,time,0,5) as time,
|
||||||
@ -254,6 +271,15 @@ SELECT
|
|||||||
FROM (VALUES (1,'blue',1),(2,'red',2)) v(time,color,value)
|
FROM (VALUES (1,'blue',1),(2,'red',2)) v(time,color,value)
|
||||||
GROUP BY 1,color ORDER BY 2,1;
|
GROUP BY 1,color ORDER BY 2,1;
|
||||||
|
|
||||||
|
-- test grouping by non-time columns with text columns with no rows in resultset
|
||||||
|
SELECT
|
||||||
|
time_bucket_gapfill(1,time,0,5) as time,
|
||||||
|
color,
|
||||||
|
min(value) as m
|
||||||
|
FROM (VALUES (1,'blue',1),(2,'red',2)) v(time,color,value)
|
||||||
|
WHERE false
|
||||||
|
GROUP BY 1,color ORDER BY 2,1;
|
||||||
|
|
||||||
-- test insert into SELECT
|
-- test insert into SELECT
|
||||||
CREATE TABLE insert_test(id INT);
|
CREATE TABLE insert_test(id INT);
|
||||||
INSERT INTO insert_test SELECT time_bucket_gapfill(1,time,1,5) FROM (VALUES (1),(2)) v(time) GROUP BY 1 ORDER BY 1;
|
INSERT INTO insert_test SELECT time_bucket_gapfill(1,time,1,5) FROM (VALUES (1),(2)) v(time) GROUP BY 1 ORDER BY 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user