mirror of
https://github.com/ent/ent.git
synced 2026-04-28 05:30:56 +03:00
doc/indexes: add partial indexes example (#2945)
This commit is contained in:
@@ -185,8 +185,7 @@ func (Card) Indexes() []ent.Index {
|
||||
|
||||
## Dialect Support
|
||||
|
||||
Indexes currently support only SQL dialects, and do not support Gremlin. Dialect specific features are allowed using
|
||||
[annotations](schema-annotations.md). For example, in order to use [index prefixes](https://dev.mysql.com/doc/refman/8.0/en/column-indexes.html#column-indexes-prefix)
|
||||
Dialect specific features are allowed using [annotations](schema-annotations.md). For example, in order to use [index prefixes](https://dev.mysql.com/doc/refman/8.0/en/column-indexes.html#column-indexes-prefix)
|
||||
in MySQL, use the following configuration:
|
||||
|
||||
```go
|
||||
@@ -216,6 +215,7 @@ CREATE INDEX `users_c1_c2_c3` ON `users`(`c1`(100), `c2`(200), `c3`)
|
||||
|
||||
Starting with v0.10, Ent running migration with [Atlas](https://github.com/ariga/atlas). This option provides
|
||||
more control on indexes such as, configuring their types or define indexes in a reverse order.
|
||||
|
||||
```go
|
||||
func (User) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
@@ -240,6 +240,11 @@ func (User) Indexes() []ent.Index {
|
||||
Annotations(
|
||||
entsql.IncludeColumns("address"),
|
||||
),
|
||||
// Define a partial index on SQLite and PostgreSQL.
|
||||
index.Fields("nickname").
|
||||
Annotations(
|
||||
entsql.IndexWhere("active"),
|
||||
),
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -257,10 +262,13 @@ CREATE INDEX `users_c4` ON `users` USING HASH (`c4`)
|
||||
CREATE FULLTEXT INDEX `users_c5` ON `users` (`c5`)
|
||||
|
||||
-- PostgreSQL only.
|
||||
CREATE INDEX `users_c5` ON `users` USING GIN (`c5`)
|
||||
CREATE INDEX "users_c5" ON "users" USING GIN ("c5")
|
||||
|
||||
-- include index-only scan on PostgreSQL.
|
||||
CREATE INDEX `users_workplace` ON `users` USING (`workplace`) INCLUDE (address)
|
||||
CREATE INDEX "users_workplace" ON "users" ("workplace") INCLUDE ("address")
|
||||
|
||||
-- Define partial index on SQLite and PostgreSQL.
|
||||
CREATE INDEX "user_nickname" ON "users" ("nickname") WHERE "active"
|
||||
```
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user