Quantcast
Channel: TimescaleDB and PostgreSQL - Timescale Community Forum
Viewing all articles
Browse latest Browse all 291

Bug report (?) : inconsistent results when doing a sum

$
0
0

I may have found a bug here. Could someone please tell me what I should look for to understand this mystery :

I have 12 devices who give me each a value over time (every 10 seconds). These values are stored in a “teleinformation” hypertable (no custom chunk_time_interval, so I guess it’s still 7 days).

When I do this :

SELECT SUM(value), time
FROM teleinformation
WHERE code_device IN ('device_1_P', 'device_2_P', 'device_3_P', 'device_4_P', 'device_5_P', 'device_6_P', 'device_7_P', 'device_8_P', 'device_9_P', 'device_10.1_P', 'device_11.1_P', 'device_12.1_P')
GROUP BY time

It takes ~200 ms in Grafana, but I get this chart with anormal spikes every 2 hours :

When I do this awful query :

WITH device_1 AS (
		SELECT value, time FROM teleinformation WHERE code_device = 'device_1_P'
	),
	device_2 AS (
		SELECT value, time FROM teleinformation WHERE code_device = 'device_2_P'		
	),
	device_3 AS (
		SELECT value, time FROM teleinformation WHERE code_device = 'device_3_P'		
	),
	device_4 AS (
		SELECT value, time FROM teleinformation WHERE code_device = 'device_4_P'		
	),
	device_5 AS (
		SELECT value, time FROM teleinformation WHERE code_device = 'device_5_P'		
	),
	device_6 AS (
		SELECT value, time FROM teleinformation WHERE code_device = 'device_6_P'		
	),
	device_7 AS (
		SELECT value, time FROM teleinformation WHERE code_device = 'device_7_P'		
	),
	device_8 AS (
		SELECT value, time FROM teleinformation WHERE code_device = 'device_8_P'		
	),
	device_9 AS (
		SELECT value, time FROM teleinformation WHERE code_device = 'device_9_P'		
	),
	device_10 AS (
		SELECT value, time FROM teleinformation WHERE code_device = 'device_10.1_P'		
	),
	device_11 AS (
		SELECT value, time FROM teleinformation WHERE code_device = 'device_11.1_P'		
	),
	device_12 AS (
		SELECT value, time FROM teleinformation WHERE code_device = 'device_12.1_P'		
	)
SELECT
	(device_1.value
	+ device_2.value
	+ device_3.value	
	+ device_4.value
	+ device_5.value
	+ device_6.value
	+ device_7.value
	+ device_8.value
	+ device_9.value
	+ device_10.value
	+ device_11.value
	+ device_12.value)
  , device_1.time
FROM device_1
JOIN device_2 ON device_1.time = device_2.time
JOIN device_3 ON device_1.time = device_3.time
JOIN device_4 ON device_1.time = device_4.time
JOIN device_5 ON device_1.time = device_5.time
JOIN device_6 ON device_1.time = device_6.time
JOIN device_7 ON device_1.time = device_7.time
JOIN device_8 ON device_1.time = device_8.time
JOIN device_9 ON device_1.time = device_9.time
JOIN device_10 ON device_1.time = device_10.time
JOIN device_11 ON device_1.time = device_11.time
JOIN device_12 ON device_1.time = device_12.time

It takes much longer (~7 s), but gives me the good result without the anormal spikes :
<can’t insert 2 images in a post as new user : see the expected result in next reply>

Could someone please tell me what could be the cause of the anormal spikes every 2 hours, and how could I investigate it ? Could it be related to the size of chunks ? Is there a simple workaround ?

12 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 291

Trending Articles