169 похожих чатов

Hey I’m looking for a tech advice: I want to estimate

the # of rows in a resultset for an OLAP query before acutally running the query on a huge table.
Motivation: return error early if the resultset estimated size is anyway too big for a client to process.

What I’m thinking now is to parse the output of EXLAIN + tune statistics for columns + run analyze more often. Is this going to work?
Or are there better solutions? 🙂

8 ответов

23 просмотра

There are much better solutions. Depending on the complexity of the query. If it were just one table, I believe there are articles (Cybertec) comes to mind, that explains what DETAILS are used to estimate the number of rows, because what the optimizer does and EXPLAIN does is open source and pretty well documented. I've done something similar to hit a single table for estimated rows from that table, as opposed to using an expensive select count()... when the actual count was NOT really important.

For a table you can use this query: ` SELECT reltuples::bigint AS estimate FROM pg_class WHERE relname = 'tablename' ;

Vitali Kotik- Автор вопроса
Stefanie Janine Stölting
For a table you can use this query: ` SELECT reltu...

Hey, thanks! It’s not that I need the total # of rows, but the # of rows that correspond to some query (WHERE + GROUP BY) 🙂

Vitali Kotik
Hey, thanks! It’s not that I need the total # of r...

Nope, the query I posted returns the numbers of records estimated. With a complex query there is no chance to estimate the numbers.

Vitali Kotik- Автор вопроса
Vitali Kotik
What is a complex query?

Anything containing joins, where, and/or group by. An estimation on such things is like rolling a dice with thousands of sites.

Vitali Kotik- Автор вопроса
Stefanie Janine Stölting
Anything containing joins, where, and/or group by....

I don’t have joins, but I do have WHERE and GROUP BY. I assumed that with different kinds of stats (https://www.postgresql.org/docs/current/planner-stats.html) planner could do that

Vitali Kotik
I don’t have joins, but I do have WHERE and GROUP ...

Well, read the source code of the planner. It's a very complex thing and it doesn't estimate the count of rows.

Похожие вопросы

Обсуждают сегодня

@MrMiscipitlick А можешь макрос написать, который будет вычислять смещение относительно переданных меток? Просто .label1-.label2, и вернуть значение.
КТ315
35
я не магистр хаскеля, но разве не может лейзи тип конвертнуться в не-лейзи запросив вычисление содержимого прям при инициализации?
deadgnom32 λ madao
100
А еще в перле можно уже @arr1 + @arr2?
Sergei Zhmylove
53
Подобного рода ;Следующие три строки это директивы ассемблера, ;которые можно не задавать, т.к.работаем в Visual Studio. ;Символ ";" - это начало однострочного комментария ...
Егор Анелькин
3
Привет всем. появился вопрос. Разрабатываю сайт, в данный момент он запущен. Хостинг beget. Добавляю на сайт яндекс метрику с помощью полей client-settings (взято отсюда http...
Andrew
2
Подскажите, где смотреть результат выполнения программы? Код: ;.686 ;Система команд процессора 686 ;.MODEL FLAT,stdcall ;Модель памяти плоская, станда...
Егор Анелькин
5
еще вопрос, допустим мы создадим char массив из 10 элементов и присвоим ему через сканф 10 символов. и выведем все символы. Хотел спросить последний элемент /0 будет включать...
Anthem
11
открыть папку в проводнике: 1 - ShellExecute 2 - ExecuteProcess 3 - OpenDocument что лучше выбрать?
Alexey Kulakov
12
Где в Астане можно купить мясо для шашлыков?
Dancing Іңұқәһүғө
21
;.686 ;Система команд процессора 686 ;.MODEL FLAT,stdcall ;Модель памяти плоская, стандартный ;вызов процедуры ;option casemap:no...
Егор Анелькин
1
Карта сайта