Re: Unnecessary buffer usage with multicolumn index, row comparison, and equility constraint

Поиск
Список
Период
Сортировка
От Ron Johnson
Тема Re: Unnecessary buffer usage with multicolumn index, row comparison, and equility constraint
Дата
Msg-id CANzqJaBQHxdipDNM5KkfTmi4H1iT6y1pc4kpqyp5OucPROuYKw@mail.gmail.com
обсуждение исходный текст
Ответ на Unnecessary buffer usage with multicolumn index, row comparison, and equility constraint  (WU Yan <4wuyan@gmail.com>)
Ответы Re: Unnecessary buffer usage with multicolumn index, row comparison, and equility constraint
Список pgsql-general
On Fri, May 10, 2024 at 11:28 PM WU Yan <4wuyan@gmail.com> wrote:
Hi everyone, first time here. Please kindly let me know if this is not the right place to ask.

I notice a simple query can read a lot of buffer blocks in a meaningless way, when
1. there is an index scan on a multicolumn index
2. there is row constructor comparison in the Index Cond
3. there is also an equality constraint on the leftmost column of the multicolumn index


## How to reproduce

I initially noticed it on AWS Aurora RDS, but it can be reproduced in docker container as well.
```bash
docker run --name test-postgres -e POSTGRES_PASSWORD=mysecretpassword -d -p 5432:5432 postgres:16.3
```

Create a table with a multicolumn index. Populate 12 million rows with random integers.
```sql
CREATE TABLE t(a int, b int);
CREATE INDEX my_idx ON t USING BTREE (a, b);

INSERT INTO t(a, b)
SELECT
    (random() * 123456)::int AS a,
    (random() * 123456)::int AS b
FROM
    generate_series(1, 12345678);

ANALYZE t;
```

Simple query that uses the multicolumn index.
```
postgres=# explain (analyze, buffers) select * from t where row(a, b) > row(123450, 123450) and a = 0 order by a, b;

Out of curiosity, why "where row(a, b) > row(123450, 123450)" instead of "where a > 123450 and b > 123450"?

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

Предыдущее
От: WU Yan
Дата:
Сообщение: Unnecessary buffer usage with multicolumn index, row comparison, and equility constraint
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Unnecessary buffer usage with multicolumn index, row comparison, and equility constraint