| От | Tom Lane |
|---|---|
| Тема | Re: Best way to know if there is a row |
| Дата | |
| Msg-id | 14451.1096381456@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | Best way to know if there is a row (Martin Marques <martin@bugs.unl.edu.ar>) |
| Список | pgsql-sql |
Martin Marques <martin@bugs.unl.edu.ar> writes:
> I need to know if there is at least one row in the relation that comes from a
> determinated query. Which is the best way to do this:
> (a) Build the query with "SELECT * ..." and after executing the query see if
> numRows()>0
> (b) Build the query with "SELECT count(*) ...", fetch the row and see if
> count>0
Either of these implies computing the entire query result set, which is
much more computation than you want. Instead doSELECT * .... LIMIT 1
and then see if you got a row or not. Aside from not computing useless
rows, the LIMIT will bias the optimizer in favor of fast-start plans.
regards, tom lane
В списке pgsql-sql по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера