Skip to content

Commit 98d2991

Browse files
committed
Update sql-create-dictionary.md
make it clear FLAT layout in dictionary is for numbers
1 parent ce2a970 commit 98d2991

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

docs/sql-create-dictionary.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ The default `INITIAL_ARRAY_SIZE` is 1,024 and default `MAX_ARRAY_SIZE` is 500,00
144144
LAYOUT(FLAT(INITIAL_ARRAY_SIZE 50000 MAX_ARRAY_SIZE 5000000))
145145
```
146146

147+
Please note that the `FLAT` layout expects the primary key to be a number which can be converted to `uint64`. If the primary key is not a number, such as a string, you should switch to the `HASHED` or `COMPLEX_KEY_HASHED` layout.
148+
147149
#### HASHED
148150
The `HASHED` layout stores the dictionary data in a hash table. This layout provides better memory usage than the `FLAT` layout, with slightly lower performance. The dictionary can contain any number of elements with any identifiers.
149151

@@ -155,6 +157,8 @@ LAYOUT(HASHED())
155157
LAYOUT(HASHED([SHARDS 1] [SHARD_LOAD_QUEUE_BACKLOG 10000] [MAX_LOAD_FACTOR 0.5]))
156158
```
157159

160+
Please note that the `HASHED` layout expects the primary key to be a number which can be converted to `uint64`. If the primary key is not a number, such as a string, Timeplus will automatically switch to the `COMPLEX_KEY_HASHED` layout. Such optimization is available for other CACHE/HASHED layouts, but not `FLAT` layout.
161+
158162
#### SPARSE_HASHED
159163
The `SPARSE_HASHED` layout is similar to the `HASHED` layout, but it is optimized for sparse data. It uses less memory than the `HASHED` layout.
160164

@@ -539,6 +543,27 @@ ON orders.customer_id = customers.c_custkey
539543
SETTINGS join_algorithm = 'direct';
540544
```
541545

546+
### Create a dictionary from a PostgreSQL table {#create_dictionary_pg}
547+
548+
For example, you can create a dictionary, referencing a PostgreSQL table:
549+
550+
```sql
551+
CREATE DICTIONARY dict_pg_table (
552+
ip string,
553+
desc string
554+
)
555+
PRIMARY KEY ip
556+
SOURCE(POSTGRESQL(HOST 'pg.aivencloud.com' PORT 28851 USER 'avnadmin' PASSWORD '..' TABLE 'ip' DB 'defaultdb'))
557+
LIFETIME(0)
558+
LAYOUT(COMPLEX_KEY_HASHED());
559+
```
560+
561+
Then you can query the dictionary with the `dict_get` function:
562+
563+
```sql
564+
SELECT dict_get('dict_pg_table','desc','192.168.1.1');
565+
```
566+
542567
## Limitations
543568
* Creating a dictionary from PostgreSQL is not supported.
544569

0 commit comments

Comments
 (0)