-
Notifications
You must be signed in to change notification settings - Fork 332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance Issue with now() - Interval in Aggregated Query #2720
Comments
Hi @fredrikIOT, thanks for reporting this issue.
Do you mean you have 50 tables like And, can you also paste the result of |
Hi @waynexia, Thank you for your follow-up. Below is the information you requested: SHOW CREATE TABLE Output for location1: CREATE TABLE IF NOT EXISTS "location1" (
"location_uid" STRING NULL,
"room_uid" STRING NULL,
"log_uid" STRING NULL,
"sensor_name" STRING NULL,
"value" DOUBLE NULL,
"ts" TIMESTAMP(3) NOT NULL,
TIME INDEX ("ts"),
PRIMARY KEY ("location_uid", "room_uid", "log_uid", "sensor_name")
) ENGINE=mito WITH( regions = 1 ) Fast query:EXPLAIN ANALYZE Output: EXPLAIN ANALYZE SELECT
DATE_BIN(INTERVAL '1 minutes', ts, '1970-01-01T00:00:00Z'::TIMESTAMP) AS ts,
sensor_name,
avg(value)
FROM "location1"
WHERE
ts > '2023-11-09 00:00:16.408'::timestamp
--ts > now() - Interval '5 hours'
and log_uid = 'Log1' and sensor_name = 'co2'
GROUP BY 1, "sensor_name" Result:
Slow query:EXPLAIN ANALYZE Output: EXPLAIN ANALYZE SELECT
DATE_BIN(INTERVAL '1 minutes', ts, '1970-01-01T00:00:00Z'::TIMESTAMP) AS ts,
sensor_name,
avg(value)
FROM "location1"
WHERE
--ts > '2023-11-09 00:00:16.408'::timestamp
ts > now() - Interval '5 hours'
and log_uid = 'Log1' and sensor_name = 'co2'
GROUP BY 1, "sensor_name" Result:
Each of the 50 tables is set up similarly to "location1", with the difference being the contents. The rationale behind this structure was to partition the data by location, as I was unable to find a method to partition based on a primary key constraint other than using greater than or equal conditions. (If there's a more straightforward approach to this partitioning, I would be open to suggestions.) Additional Note: This is the log from today: |
Thanks for those information. I've found the reason. Writing fix patch |
Could you check if #2723 works for you @fredrikIOT ? I can make a nightly release if you need |
Could you please create a nightly release? I'd like to test the patch. Thank you for your prompt response and support. |
Now I get similar performance on both queries: Thanks! |
Now this issue is back. I have tested with: When using |
I am not sure when this started btw. I don't think this issue was in the |
Thanks for your report! (again) I'm looking into this. Looks like our tests are not enough... |
@waynexia How is this issue progressing? |
What type of bug is this?
Performance issue
What subsystems are affected?
Standalone mode, Frontend
What happened?
Environment:
Issue Summary:
When executing an aggregated query over the previous 5 hours, using
now() - Interval '5 hours'
in the WHERE clause significantly slows down the query compared to using a hardcoded timestamp.Expected Behavior:
Both queries should have similar execution times since they are theoretically querying the same time window.
Actual Behavior:
The query using
now() - Interval '5 hours'
is approximately 4 times slower than the query with a hardcoded timestamp.First Query (slow query):
Second Query (fast query):
Hypothesis:
It seems that the dynamic calculation of
now() - Interval '5 hours'
might be affecting the query optimizer's ability to efficiently execute the query. However, the exact cause is unclear and needs investigation.What operating system did you use?
Docker (installed on Ubuntu 22.04.3 LTS)
Relevant log output and stack trace
No response
How can we reproduce the bug?
Testing Setup:
Steps to Reproduce:
now() - INTERVAL '5 hours'
to filter records from the last 5 hours.Performance Metrics:
now()
, took approximately 4.6 seconds to complete.Queries:
Took about 4.6 seconds, while the query below used about 1.45 seconds:
Also, my last query was actually querying a bigger time windows than 5 hours, and returned more values, and still was much faster.
The text was updated successfully, but these errors were encountered: