[ZBX-16213] TimescaleDB query optimization Created: 2019 Jun 04  Updated: 2024 Apr 10  Resolved: 2019 Jul 05

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: API (A), Frontend (F)
Affects Version/s: None
Fix Version/s: 4.4.0alpha1, 4.4 (plan)

Type: Problem report Priority: Minor
Reporter: Rostislav Palivoda Assignee: Andrejs Verza
Resolution: Fixed Votes: 0
Labels: TimescaleDB
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Team: Team B
Team: Team B
Sprint: Sprint 53 (Jun 2019), Sprint 54 (Jul 2019)
Story Points: 1.5

 Description   

Today we learned that Zabbix generates a particular query that is non-optimal for TimescaleDB.

This is because TimescaleDB does not do chunk exclusion when the constraint involves a subquery. To be performant TimescaleDB needs to scan only a subset of chunks. Please see the query below:

SELECT * FROM history_uint h WHERE h.itemid=$1 AND h.clock=(SELECT MAX(h2.clock) FROM history_uint h2 WHERE h2.itemid=$1 AND h2.clock>$2) ORDER BY h.ns DESC LIMIT 1 

In this user's query, there is the constraint h.clock=(SELECT ...). The problem here is that chunk pruning that would speed up this query can't happen because the constraint involves a subquery. Thus the user needs to explicitly add an extra time constraint, h2.clock>$2, to the top query.
 
So, while the users are able to go in and tweak this query, we imagine it would be a better  experience if this was enabled by default on the generated query. This would result in the best performance out-of-the-box and you will reduce friction from any manual configuration required.
 
 



 Comments   
Comment by Andrejs Verza [ 2019 Jun 11 ]

Resolved in development branch feature/ZBX-16213-4.0.

Comment by Andrejs Verza [ 2019 Jul 05 ]

Fixed in:

Generated at Sat Apr 20 04:27:18 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.