Skip to content

Commit

Permalink
Adding indexes to big_map_contents table (#972)
Browse files Browse the repository at this point in the history
* adding indexes to big_map_contents table and running scalafmt

* fixing tests
  • Loading branch information
piotrkosecki authored Mar 18, 2021
1 parent 56b5808 commit 7958acf
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ class GenericPlatformDiscoveryOperationsTest
"Operation group id",
DataType.String,
None,
KeyType.NonKey,
KeyType.UniqueKey,
"big_map_contents"
),
Attribute("value", "Value", DataType.String, None, KeyType.NonKey, "big_map_contents"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,15 @@ trait Tables {

/** Primary key of BigMapContents (database name big_map_contents_pkey) */
val pk = primaryKey("big_map_contents_pkey", (bigMapId, key))

/** Index over (bigMapId) (database name big_map_id_idx) */
val index1 = index("big_map_id_idx", bigMapId)

/** Index over (bigMapId,operationGroupId) (database name combined_big_map_operation_group_ids_idx) */
val index2 = index("combined_big_map_operation_group_ids_idx", (bigMapId, operationGroupId))

/** Index over (operationGroupId) (database name operation_group_id_idx) */
val index3 = index("operation_group_id_idx", operationGroupId)
}

/** Collection-like TableQuery object for table BigMapContents */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,20 @@ case class BigMapsOperations[Profile <: ExPostgresProfile](profile: Profile) ext
case Contract.BigMapCopy(_, Decimal(sourceId), Decimal(destinationId)) =>
Tables.BigMapContents
.filter(_.bigMapId === sourceId)
.map(it => (destinationId, it.key, it.keyHash, it.operationGroupId, it.value, it.blockLevel, it.timestamp, it.cycle, it.period))
.map(
it =>
(
destinationId,
it.key,
it.keyHash,
it.operationGroupId,
it.value,
it.blockLevel,
it.timestamp,
it.cycle,
it.period
)
)
.result
.headOption
}
Expand Down
4 changes: 4 additions & 0 deletions sql/conseil.sql
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,10 @@ CREATE TABLE tezos.big_map_contents (
PRIMARY KEY (big_map_id, key)
);

CREATE INDEX big_map_id_idx ON tezos.big_map_contents USING btree (big_map_id);
CREATE INDEX operation_group_id_idx ON tezos.big_map_contents USING btree (operation_group_id);
CREATE INDEX combined_big_map_operation_group_ids_idx ON tezos.big_map_contents USING btree (big_map_id, operation_group_id);

CREATE TABLE tezos.originated_account_maps (
big_map_id numeric,
account_id character varying,
Expand Down

0 comments on commit 7958acf

Please sign in to comment.