Skip to content

Commit 47f7b38

Browse files
author
Carl Sverre
committed
Added hash index docs and test
fixes #41
1 parent acbe7aa commit 47f7b38

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This package is currently in a pre-release beta, please use with caution and ope
2121
- [Shard Keys](#shard-keys)
2222
- [Sort Keys](#sort-keys)
2323
- [Unique Keys](#unique-keys)
24+
- [Hash Keys](#hash-keys)
2425
- [Series Timestamps](#series-timestamps)
2526
- [Computed Columns](#computed-columns)
2627
- [Increment Columns without Primary Key](#increment-columns-without-primary-key)
@@ -338,6 +339,20 @@ Schema::create('table', function (Blueprint $table) {
338339
});
339340
```
340341

342+
### Hash Keys
343+
344+
You can add a `hash key` to your tables using the third argument to the `index`
345+
function. Note that by default, indexes on Universal Storage Tables
346+
(Columnstore) are always hash indexes, so a simple `.index(foo)` is usually
347+
sufficient. On Rowstore tables this syntax is needed to create a hash index.
348+
349+
```php
350+
Schema::create('table', function (Blueprint $table) {
351+
$table->string('name');
352+
$table->index('name', 'name_idx', 'hash');
353+
});
354+
```
355+
341356
### Series Timestamps
342357
To denote a column as a series timestamp, use the `seriesTimestamp` column modifier.
343358

tests/Hybrid/CreateTable/MiscCreateTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ public function all_keys_are_added_in_create_columnstore()
2424
$blueprint = $this->createTable(function (Blueprint $table) {
2525
$table->string('primary')->primary('name1');
2626
$table->string('index')->index('name2');
27+
$table->string('foo');
28+
$table->index('foo', 'name3', 'hash');
2729
$table->string('fulltext')->fulltext('name5')->charset('utf8');
2830
});
2931

3032
$this->assertCreateStatement(
3133
$blueprint,
32-
'create table `test` (`primary` varchar(255) not null, `index` varchar(255) not null, `fulltext` varchar(255) character set utf8 not null, primary key `name1`(`primary`), index `name2`(`index`), fulltext `name5`(`fulltext`))'
34+
'create table `test` (`primary` varchar(255) not null, `index` varchar(255) not null, `foo` varchar(255) not null, `fulltext` varchar(255) character set utf8 not null, index `name3` using hash(`foo`), primary key `name1`(`primary`), index `name2`(`index`), fulltext `name5`(`fulltext`))'
3335
);
3436
}
3537

0 commit comments

Comments
 (0)