B
B
BestJS2018-05-03 23:26:39
PostgreSQL
BestJS, 2018-05-03 23:26:39

How to make fast unique fetch from postgresql?

There is a table:
5aeb6e34b9733865091734.png
You need to quickly get the last unique values ​​for the "radio" field from the table.
That is, for the "radio" field, the last value is the value of the "track" field.
Having rummaged through the Internet, I found only this option: 5aeb701994ca0004359774.png
But it runs for 5 minutes, which is not very good.
I would be grateful for any advice

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
asd111, 2018-05-04
@asd111

select *
from tracks
group by radio;

M
Melkij, 2018-05-04
@melkij

Is there a list of necessary radios separately or do you need to search for the same plate?
If you search on the same plate, then you need loose index scan . A stupid planner himself cannot do this, you have to explain it manually.
If the list is separate, then a simple lateral join of the subquery will be more compact.
Here , from slides 30 to 46
, the btree(radio, date) index is required, if I understand correctly on what basis you want to determine the "last" value.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question