Skip to main content
don't link to outdated Postgres versions
Source Link
user330315
user330315

Postgres supports to some extend clustered indexes, which is what you suggest by removing and reinserting the data.

In fact, removing and reinserting the data in the order you want will not change the time the query takes. Postgres does not know the order of the data.

If you know that the table's data does not change. Then cluster the data based on the index you create.

This operation reorders the table based on the order in the index. It is very effective until you update the table. The syntax is:

CLUSTER tableName USING IndexName;

See enter link description herethe manual for details.

I also recommend you use

explain <query>;

to compare two queries, before and after an index. Or before and after clustering.

Postgres supports to some extend clustered indexes, which is what you suggest by removing and reinserting the data.

In fact, removing and reinserting the data in the order you want will not change the time the query takes. Postgres does not know the order of the data.

If you know that the table's data does not change. Then cluster the data based on the index you create.

This operation reorders the table based on the order in the index. It is very effective until you update the table. The syntax is:

CLUSTER tableName USING IndexName;

See enter link description here for details.

I also recommend you use

explain <query>;

to compare two queries, before and after an index. Or before and after clustering.

Postgres supports to some extend clustered indexes, which is what you suggest by removing and reinserting the data.

In fact, removing and reinserting the data in the order you want will not change the time the query takes. Postgres does not know the order of the data.

If you know that the table's data does not change. Then cluster the data based on the index you create.

This operation reorders the table based on the order in the index. It is very effective until you update the table. The syntax is:

CLUSTER tableName USING IndexName;

See the manual for details.

I also recommend you use

explain <query>;

to compare two queries, before and after an index. Or before and after clustering.

Source Link
dmg
  • 4.6k
  • 2
  • 20
  • 26

Postgres supports to some extend clustered indexes, which is what you suggest by removing and reinserting the data.

In fact, removing and reinserting the data in the order you want will not change the time the query takes. Postgres does not know the order of the data.

If you know that the table's data does not change. Then cluster the data based on the index you create.

This operation reorders the table based on the order in the index. It is very effective until you update the table. The syntax is:

CLUSTER tableName USING IndexName;

See enter link description here for details.

I also recommend you use

explain <query>;

to compare two queries, before and after an index. Or before and after clustering.