questdb / questdb/questdb

Better handling of intervals in queries

Open
#4,155 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

New feature
Dominant language
Java
Stars
17.3k
Forks
1.6k
Avg merge
5d 10h
Merged PRs (30d)
28

Description

Is your feature request related to a problem?

We found that posing queries having a where statement looking something like:
... WHERE (timestamp BETWEEN a AND b) OR (timestamp BETWEEN c AND d) ...
resulted in row scans over the whole dataset which lead to suboptimal performance.

Currently what we did is we did a query of a single timestamp range and essentially pre-processing so we grabbed the min( start_timestamps ) and the max(end_timestamps) then after receiving the dataset we split it up on our own. Even though we processed and transferred more data than necessary it was faster than the full record scan.

Describe the solution you'd like.

Since queries like:
WHERE (timestamp BETWEEN a AND b) AND (timestamp BETWEEN c AND d) ...
i.e. bolean AND operator instead of OR resulted in a query plan using interval forward scan and by the looks of it the intervals could be an array of multiple intervals.

My direct idea would be to aggregate the given intervals from the query and do a pre-processing step to determine the k number of sorted and non-overlaping intervals based of the query, then use this list of non-overlapping queries as input to the interval forward scan.

Describe alternatives you've considered.

As an alternative you could in the query engine do something similar to what we resorted to, generate the interval from min(start_timestamps) to max(end_timestamps) and use interval scan on that interval combined with filter on timestamp.

Full Name:

Daniel Wedlund

Affiliation:

Mounte AB

Additional context

Had a quick chat on slack regarding this.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported SQL queries with OR- and AND-connected timestamp intervals, then trace the query engine's interval forward scan and interval handling. The work is complete when multiple sorted, non-overlapping intervals can be used for the scan without a full dataset scan, with the query results matching the timestamp predicates.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
databases, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.