However, I cannot add the created_date in them. GIN indexes are supported in YugabyteDB as of version 2.11 and the feature roadmap is tracked in #7850 With this single-table design, I can create GIN indexes on those arrays: Other use cases involve getting posts by tag_idor by group_id to fill the feed list. For YugabyteDB, it would be better to set the sharding options explicitly, with a descending order: PRIMARY KEY (user_id HASH, created_date DESC post_id ASC). This is something to decide when knowing all access patterns. The advantage is to allow fast access to a time range when looking at one user posts. The drawback of adding created_date in primary key is full rewrite of the whole document in case the created_date is updated, which is probably not the case here. But for the primary key, I'm adding the date. The business key is user_id, post_id and I enforce it with a UNIQUE constraint. So this is equivalent to PRIMARY KEY (user_id HASH, created_date ASC, post_id ASC). YugabyteDB default is hash on the first column, and range on next. I didn't mention the sharding method in the CREATE statement, to keep the code compatible with PostgreSQL. In YugabyteDB, a table is stored clustered on the primary key, to allow fast point and range access without a secondary index. In PostgreSQL, this creates a heap table and a secondary index for the primary key. This follows a single-table data model, each row being a document with its content and lists of group_ids and tag_ids. Enter fullscreen mode Exit fullscreen mode
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |