Re: offset and limit in update and subselect

Поиск
Список
Период
Сортировка
От Lincoln Yeoh
Тема Re: offset and limit in update and subselect
Дата
Msg-id 3.0.5.32.20010225194248.00b47320@192.228.128.13
обсуждение исходный текст
Ответ на Re: offset and limit in update and subselect  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Re: offset and limit in update and subselect  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
At 05:07 PM 2/24/01 -0500, Tom Lane wrote:
>is not a defined concept according to SQL.  Even if we allowed queries
>such as you've described, the results would not be well-defined, but
>would change at the slightest provocation.  The implementation feels
>itself entitled to rearrange tuple order whenever the whim strikes it.
>
>As the documentation tries hard to make plain, LIMIT/OFFSET are only
>guaranteed to produce reproducible results if there's also an ORDER BY
>that constrains the tuples into a unique ordering.

Hi,

Would it then be fine to use update ... limit in the following scenario?

I have a todo queue:

create table todo ( task text, pid int default 0);

The tasks are inserted into the todo table.

Then the various worker processes do the following update to grab tasks
without duplication.

update todo set pid=$mypid where pid=0 limit 1;

For me it doesn't matter what which row each worker gets, as long as they
only get one each and they are not the same.

What would the performance impact of "order by" be in a LIMIT X case? Would
it require a full table scan?

Thanks,
Link.



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Ola Sundell
Дата:
Сообщение: jdbc driver hack
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: PL/SQL-to-PL/pgSQL-HOWTO + PL/pgSQL documentation