markdown PostgreSQL索引提示

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown PostgreSQL索引提示相关的知识,希望对你有一定的参考价值。

#### Index order matters!
 
For exapmle **polymor**, Rails 4 or older created the index such as

```ruby
add_index "http_responses", ["originator_type", "originator_id"], name: "index_http_responses_on_originator_id_and_originator_type", using: :btree
```

it's certainly slower than

```ruby
add_index "http_responses", ["originator_id", "originator_type"], name: "index_http_responses_on_originator_id_and_originator_type", using: :btree
```


#### Algorthm concurrently

And when you try to remove the indexes on production, it might be locked because it's using.
Try to add index by data migration such as

```ruby
add_index :tables, ["originator_id", "originator_type"], algorithm: :concurrently 
```

by append `algorithm: :concurrently` to avoid potential crushes.

The caveat is that [concurrent indexes must be created outside a transaction](https://www.postgresql.org/docs/9.2/sql-createindex.html#SQL-CREATEINDEX-CONCURRENTLY). By default, ActiveRecord migrations are run inside a transaction.

以上是关于markdown PostgreSQL索引提示的主要内容,如果未能解决你的问题,请参考以下文章

国际新闻:PostgreSQL 14.4 发布!

国际新闻:PostgreSQL 14.4 发布!

markdown PostgreSQL命令行备忘单

markdown Postgresql杀挂查询

markdown PostgreSQL的

markdown 更改postgreSQL用户密码