@nsshunt/stsdatamanagement 1.18.99 → 1.18.101
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -0
- package/db-scripts/builddb.sql +35 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,3 +20,117 @@ docker run --name postgres-5432 -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d --
|
|
|
20
20
|
-c max_parallel_workers_per_gather=3 \
|
|
21
21
|
-c max_parallel_workers=6 \
|
|
22
22
|
-c max_parallel_maintenance_workers=3
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
/* Samples Data
|
|
27
|
+
{"id":"_b8b74a73_3275_4094_93b1_64a533c5924c_0_0fhir02_0","_resourceType":"Person","name":[{"family":"Mccall","given":"Shane","use":"usual"}],"text":{"div":"Updated record 0","status":"generated"}}
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
select count(*) from stsresource;
|
|
31
|
+
|
|
32
|
+
/* Create General Search Indexes */
|
|
33
|
+
|
|
34
|
+
/* GIN Index */
|
|
35
|
+
--drop index idx_stsresource_gin;
|
|
36
|
+
CREATE INDEX idx_stsresource_gin ON stsresource USING GIN (resdesc_jsonb);
|
|
37
|
+
|
|
38
|
+
/* btree indexes */
|
|
39
|
+
--drop index idx_stsresource_id;
|
|
40
|
+
--We don't use where here becuase all FHIR resources will have an id field
|
|
41
|
+
CREATE INDEX idx_stsresource_id ON stsresource ((resdesc_jsonb->>'id'));
|
|
42
|
+
|
|
43
|
+
-- Create Indexes for FHIR resources
|
|
44
|
+
|
|
45
|
+
--DROP INDEX idx_stsresource_given;
|
|
46
|
+
CREATE INDEX idx_stsresource_given
|
|
47
|
+
ON stsresource ((resdesc_jsonb->'name'->0->>'given'))
|
|
48
|
+
WHERE resdesc_jsonb->>'_resourceType' = 'Person';
|
|
49
|
+
|
|
50
|
+
--drop index idx_stsresource_family;
|
|
51
|
+
CREATE INDEX idx_stsresource_family ON stsresource ((resdesc_jsonb->'name'->0->>'family'))
|
|
52
|
+
WHERE resdesc_jsonb->>'_resourceType' = 'Person';
|
|
53
|
+
|
|
54
|
+
--drop index idx_stsresource_text_div_01;
|
|
55
|
+
CREATE INDEX idx_stsresource_text_div_01
|
|
56
|
+
ON stsresource ((resdesc_jsonb->'text'->>'div'))
|
|
57
|
+
WHERE resdesc_jsonb->>'_resourceType' = 'Person';
|
|
58
|
+
|
|
59
|
+
/* btree indexes - alternate method - for queries, quotes will be need '"<search string>"' */
|
|
60
|
+
--drop index idx_stsresource_text_div_02;
|
|
61
|
+
CREATE INDEX idx_stsresource_text_div_02
|
|
62
|
+
ON stsresource ((resdesc_jsonb#>'{text,div}'))
|
|
63
|
+
WHERE (resdesc_jsonb#>'{_resourceType}')::text = '"Person"';
|
|
64
|
+
|
|
65
|
+
/* Queries using our indexes */
|
|
66
|
+
|
|
67
|
+
/* Get records using the GIN index */
|
|
68
|
+
SELECT *
|
|
69
|
+
FROM stsresource
|
|
70
|
+
WHERE resdesc_jsonb @> '{"_resourceType": "Person"}'
|
|
71
|
+
AND resdesc_jsonb @> '{"name": [{"family": "Adams"}]}';
|
|
72
|
+
|
|
73
|
+
SELECT oid, resdesc_jsonb#>'{text,div}' AS text_div
|
|
74
|
+
FROM stsresource
|
|
75
|
+
WHERE resdesc_jsonb @> '{"_resourceType": "Person"}'
|
|
76
|
+
AND resdesc_jsonb @> '{"text": {"div": "New Record 100"}}';
|
|
77
|
+
|
|
78
|
+
/* Get record using the BTREE index given */
|
|
79
|
+
SELECT resdesc_jsonb->'id' as id,
|
|
80
|
+
resdesc_jsonb->'name'->0->>'given' as given,
|
|
81
|
+
resdesc_jsonb->'name'->0->>'family' as family,
|
|
82
|
+
resdesc_jsonb->'name' as name
|
|
83
|
+
FROM stsresource
|
|
84
|
+
WHERE resdesc_jsonb->>'_resourceType' = 'Person'
|
|
85
|
+
AND resdesc_jsonb->'name'->0->>'given' >= 'y' and resdesc_jsonb->'name'->0->>'given' < 'yzzzzzzzzzzzzz'
|
|
86
|
+
AND validto is null
|
|
87
|
+
ORDER BY family, given, id
|
|
88
|
+
LIMIT 20;
|
|
89
|
+
|
|
90
|
+
/* Get record using the BTREE index 01 */
|
|
91
|
+
SELECT oid, resdesc_jsonb#>'{text,div}' AS text_div
|
|
92
|
+
FROM stsresource
|
|
93
|
+
WHERE resdesc_jsonb->>'_resourceType' = 'Person'
|
|
94
|
+
AND resdesc_jsonb->'text'->>'div' = 'New Record 200';
|
|
95
|
+
|
|
96
|
+
/* Get record using the BTREE index 02 */
|
|
97
|
+
SELECT oid, resdesc_jsonb#>'{text,div}' AS text_div
|
|
98
|
+
FROM stsresource
|
|
99
|
+
WHERE resdesc_jsonb->>'_resourceType' = 'Person'
|
|
100
|
+
AND resdesc_jsonb#>'{text,div}' = '"New Record 400"';
|
|
101
|
+
|
|
102
|
+
/* Query using id index */
|
|
103
|
+
SELECT oid, resdesc_jsonb->>'id' as id, *
|
|
104
|
+
FROM stsresource
|
|
105
|
+
WHERE resdesc_jsonb->>'id' >= '_b' and resdesc_jsonb->>'id' < '_bzzzzzzzzzzzz'
|
|
106
|
+
ORDER BY resdesc_jsonb->>'id'
|
|
107
|
+
LIMIT 20;
|
|
108
|
+
|
|
109
|
+
/* Query using given index */
|
|
110
|
+
SELECT distinct given, family
|
|
111
|
+
FROM (
|
|
112
|
+
SELECT resdesc_jsonb->'name'->0->>'given' as given, resdesc_jsonb->'name'->0->>'family' as family
|
|
113
|
+
FROM stsresource
|
|
114
|
+
WHERE resdesc_jsonb->>'_resourceType' = 'Person'
|
|
115
|
+
AND validto is null
|
|
116
|
+
AND resdesc_jsonb->'name'->0->>'given' >= 'a'
|
|
117
|
+
AND resdesc_jsonb->'name'->0->>'given' < 'azzzzzzz'
|
|
118
|
+
)
|
|
119
|
+
ORDER BY given DESC
|
|
120
|
+
LIMIT 20;
|
|
121
|
+
|
|
122
|
+
/* Query using family and given indexes */
|
|
123
|
+
SELECT distinct given, family
|
|
124
|
+
FROM (
|
|
125
|
+
SELECT resdesc_jsonb->'name'->0->>'given' as given, resdesc_jsonb->'name'->0->>'family' as family
|
|
126
|
+
FROM stsresource
|
|
127
|
+
WHERE resdesc_jsonb->>'_resourceType' = 'Person'
|
|
128
|
+
AND validto is null
|
|
129
|
+
AND resdesc_jsonb->'name'->0->>'given' >= 'a'
|
|
130
|
+
AND resdesc_jsonb->'name'->0->>'given' < 'azzzzzzz'
|
|
131
|
+
AND resdesc_jsonb->'name'->0->>'family' >= 'y'
|
|
132
|
+
AND resdesc_jsonb->'name'->0->>'family' < 'yzzzzzzzzzzzz'
|
|
133
|
+
)
|
|
134
|
+
ORDER BY given DESC
|
|
135
|
+
LIMIT 20;
|
|
136
|
+
|
package/db-scripts/builddb.sql
CHANGED
|
@@ -381,6 +381,9 @@ ALTER FUNCTION public.delete_stsresource_latest(character varying, character var
|
|
|
381
381
|
OWNER TO postgres;
|
|
382
382
|
|
|
383
383
|
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
384
387
|
-- Table: public.stsentity
|
|
385
388
|
|
|
386
389
|
-- DROP TABLE public.stsentity;
|
|
@@ -824,3 +827,35 @@ ALTER FUNCTION public.delete_stsentity_latest(character varying, character varyi
|
|
|
824
827
|
OWNER TO postgres;
|
|
825
828
|
|
|
826
829
|
|
|
830
|
+
/* Create General Search Indexes */
|
|
831
|
+
|
|
832
|
+
/* GIN Index */
|
|
833
|
+
--drop index idx_stsresource_gin;
|
|
834
|
+
CREATE INDEX idx_stsresource_gin ON stsresource USING GIN (resdesc_jsonb);
|
|
835
|
+
|
|
836
|
+
/* btree indexes */
|
|
837
|
+
--drop index idx_stsresource_id;
|
|
838
|
+
--We don't use where here becuase all FHIR resources will have an id field
|
|
839
|
+
CREATE INDEX idx_stsresource_id ON stsresource ((resdesc_jsonb->>'id'));
|
|
840
|
+
|
|
841
|
+
-- Create Indexes for FHIR resources
|
|
842
|
+
|
|
843
|
+
--DROP INDEX idx_stsresource_given;
|
|
844
|
+
CREATE INDEX idx_stsresource_given
|
|
845
|
+
ON stsresource ((resdesc_jsonb->'name'->0->>'given'))
|
|
846
|
+
WHERE resdesc_jsonb->>'_resourceType' = 'Person';
|
|
847
|
+
|
|
848
|
+
--drop index idx_stsresource_family;
|
|
849
|
+
CREATE INDEX idx_stsresource_family ON stsresource ((resdesc_jsonb->'name'->0->>'family'))
|
|
850
|
+
WHERE resdesc_jsonb->>'_resourceType' = 'Person';
|
|
851
|
+
|
|
852
|
+
--drop index idx_stsresource_text_div_01;
|
|
853
|
+
CREATE INDEX idx_stsresource_text_div_01
|
|
854
|
+
ON stsresource ((resdesc_jsonb->'text'->>'div'))
|
|
855
|
+
WHERE resdesc_jsonb->>'_resourceType' = 'Person';
|
|
856
|
+
|
|
857
|
+
/* btree indexes - alternate method - for queries, quotes will be need '"<search string>"' */
|
|
858
|
+
--drop index idx_stsresource_text_div_02;
|
|
859
|
+
CREATE INDEX idx_stsresource_text_div_02
|
|
860
|
+
ON stsresource ((resdesc_jsonb#>'{text,div}'))
|
|
861
|
+
WHERE (resdesc_jsonb#>'{_resourceType}')::text = '"Person"';
|