Skip to content
Advertisement

Postgresql select max query takes long time

I have the following structure in a table in my database. Below I list a part of the existing data.

https://drive.google.com/file/d/1DrQd6kb523wUZDaqhvkx6WBQxJ3wNT3n/view?usp=sharing

My data in text format

I basically have sensors for temperature, humidity, wind speed and wind direction, and I store this information every 30s in the bank. are already have a certain amount of records. I’m having a problem with a select, I don’t know if I’m doing it wrong, but I need to select the last value registered in the bank from the location and sensor I have this as select

But the return time for this consultation is too high, what is wrong with my consultation?

Regards

Advertisement

Answer

With this index

this should be quite fast:

On a test table with 25 million rows and 100 distinct sensors and 100 distinct locations, I get this execution plan:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement