Grabbing Newest Records From Duplicates
От | Travis Whitton |
---|---|
Тема | Grabbing Newest Records From Duplicates |
Дата | |
Msg-id | cf9b4f3e0703160828s2cc0b9v6c01db6e8634e37e@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: Grabbing Newest Records From Duplicates
|
Список | pgsql-sql |
Given the following test table, I want to grab only the newest record and disregard any older duplicates based on name. Isthis the most efficient way to do it? Will the indicies even make a difference? The table below demonstrates a simple proofof concept. My final table will have millions of records; however, the test I'm doing now does not seem to use the indicies(probably because there are too few records?). <br /><br />optin=# \d test<br /> Table "public.test"<br /> Column| Type | Modifiers<br />--------+---------+-----------<br /> name | text |<br /> time | date |<br /> id | integer |<br />Indexes:<br /> "idx_name" btree (name) <br /> "idx_time" btree ("time")<br /><br />optin=#explain select * from test t1 where not exists (select 1 from test t2 where <a href="http://t2.name">t2.name</a>= <a href="http://t1.name">t1.name</a> and t2.time > t1.time);<br /><br />Thanks,<br/>Travis<br /><br />
В списке pgsql-sql по дате отправления: