Skip to content

Commit c66b1a8

Browse files
authored
Merge pull request #625 from kuba--/docs-update/index
Update an index note about good practice for bitmaps.
2 parents ffddc26 + ca5d320 commit c66b1a8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

docs/using-gitbase/indexes.md

+16
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ Indexes are implemented as bitmaps using [pilosa](https://github.com/pilosa/pilo
77
Thus, to create indexes you must specify pilosa as the type of index. You can find some examples in the [examples](./examples.md#create-an-index-for-columns-on-a-table) section about managing indexes.
88

99
Note that you can create an index either **on one or more columns** or **on a single expression**.
10+
In practice, having multiple indexes - one per column is better and more flexible than one index for multiple columns. It is because of data structures (bitmaps) used to represent index values.
11+
Even if you have one index on multiple columns, every columns is stored in independent _field_.
12+
Merging those _fields_ by any logic operations is fast and much more flexible. The main difference of having multiple columns per index is, it internally calculates intersection across columns, so the index won't be used if you use _non_ `AND` operation in a filter, e.g.:
13+
14+
With index on (`A`, `B`), the index will be used for following query:
15+
```sql
16+
SELECT * FROM T WHERE A='...' AND B='...'
17+
```
18+
But it won't be used if we change logic operation to, e.g.:
19+
```sql
20+
SELECT * FROM T WHERE A='...' OR B='...'
21+
```
22+
23+
So it's more flexible with two indexes - one on `A`, and the second on `B`.
24+
For the first query the intersection of two _fields_ will be returned
25+
and for the second query also two indexes will be used and the result will be a union.
1026

1127
You can find some more examples in the [examples](./examples.md#create-an-index-for-columns-on-a-table) section.
1228

0 commit comments

Comments
 (0)