Why does CREATE INDEX CONCURRENTLY need two scans?

Поиск
Список
Период
Сортировка
От Joshua Ma
Тема Why does CREATE INDEX CONCURRENTLY need two scans?
Дата
Msg-id CAG9XPVn_oYgssW5W7K5zAq6fa5RiTOGCLMnE7rovW-3fe9a3fw@mail.gmail.com
обсуждение исходный текст
Ответы Re: Why does CREATE INDEX CONCURRENTLY need two scans?  (Michael Paquier <michael.paquier@gmail.com>)
Список pgsql-general
Hi all,

I was curious about why CONCURRENTLY needs two scans to complete - from the documentation on HOT (access/heap/README.HOT), it looks like the process is:

1) insert pg_index entry, wait for relevant in-progress txns to finish (before marking index open for inserts, so HOT updates won't write incorrect index entries)
2) build index in 1st snapshot, mark index open for inserts
3) in 2nd snapshot, validate index and insert missing tuples since first snapshot, mark index valid for searches

Why are two scans necessary? What would break if it did something like the following?

1) insert pg_index entry, wait for relevant txns to finish, mark index open for inserts
2) build index in a single snapshot, mark index valid for searches

Wouldn't new inserts update the index correctly? Between the snapshot and index-updating txns afterwards, wouldn't all updates be covered?

To be clear, I'm not trying to suggest any changes, just wondering what's missing from my mental model. :)

Thanks!
Josh

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

Предыдущее
От: Andy Colson
Дата:
Сообщение: Re: Partial index-based load balancing
Следующее
От: Michael Paquier
Дата:
Сообщение: Re: Why does CREATE INDEX CONCURRENTLY need two scans?