Showing
3 changed files
with
128 additions
and
68 deletions
... | ... | @@ -22,51 +22,71 @@ DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_views_by_tenant_and_customer |
22 | 22 | DROP TABLE IF EXISTS thingsboard.entity_views; |
23 | 23 | |
24 | 24 | CREATE TABLE IF NOT EXISTS thingsboard.entity_views ( |
25 | -id timeuuid, | |
26 | -entity_id timeuuid, | |
27 | -entity_type text, | |
28 | -tenant_id timeuuid, | |
29 | -customer_id timeuuid, | |
30 | -name text, | |
31 | -keys text, | |
32 | -start_ts bigint, | |
33 | -end_ts bigint, | |
34 | -search_text text, | |
35 | -additional_info text, | |
36 | -PRIMARY KEY (id, tenant_id, customer_id) | |
25 | + id timeuuid, | |
26 | + entity_id timeuuid, | |
27 | + entity_type text, | |
28 | + tenant_id timeuuid, | |
29 | + customer_id timeuuid, | |
30 | + name text, | |
31 | + keys text, | |
32 | + start_ts bigint, | |
33 | + end_ts bigint, | |
34 | + search_text text, | |
35 | + additional_info text, | |
36 | + PRIMARY KEY (id, entity_id, tenant_id, customer_id) | |
37 | 37 | ); |
38 | 38 | |
39 | 39 | CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_name AS |
40 | -SELECT * | |
41 | -from thingsboard.entity_views | |
42 | -WHERE entity_id IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL | |
43 | -PRIMARY KEY (tenant_id, name, id, entity_id, customer_id) | |
44 | -WITH CLUSTERING ORDER BY (name ASC, id DESC, entity_id DESC, customer_id DESC); | |
40 | + SELECT * | |
41 | + from thingsboard.entity_views | |
42 | + WHERE tenant_id IS NOT NULL | |
43 | + AND entity_id IS NOT NULL | |
44 | + AND customer_id IS NOT NULL | |
45 | + AND name IS NOT NULL | |
46 | + AND id IS NOT NULL | |
47 | + PRIMARY KEY (tenant_id, name, id, customer_id, entity_id) | |
48 | + WITH CLUSTERING ORDER BY (name ASC, id DESC, customer_id DESC); | |
45 | 49 | |
46 | 50 | CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_search_text AS |
47 | -SELECT * | |
48 | -from thingsboard.entity_views | |
49 | -WHERE entity_id IS NOT NULL AND search_text IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL | |
50 | -PRIMARY KEY (tenant_id, search_text, id, customer_id, name) | |
51 | -WITH CLUSTERING ORDER BY (search_text ASC, customer_id ASC, id DESC, name DESC); | |
51 | + SELECT * | |
52 | + from thingsboard.entity_views | |
53 | + WHERE tenant_id IS NOT NULL | |
54 | + AND entity_id IS NOT NULL | |
55 | + AND customer_id IS NOT NULL | |
56 | + AND search_text IS NOT NULL | |
57 | + AND id IS NOT NULL | |
58 | + PRIMARY KEY (tenant_id, search_text, id, customer_id, entity_id) | |
59 | + WITH CLUSTERING ORDER BY (search_text ASC, id DESC, customer_id DESC); | |
52 | 60 | |
53 | -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_entity_and_search_text AS | |
54 | -SELECT * | |
55 | -from thingsboard.entity_views | |
56 | -WHERE entity_id IS NOT NULL AND search_text IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL | |
57 | -PRIMARY KEY (tenant_id, entity_id, search_text, id, customer_id, name) | |
58 | -WITH CLUSTERING ORDER BY (entity_id ASC, search_text ASC, id DESC, name DESC); | |
61 | +CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_entity AS | |
62 | + SELECT * | |
63 | + from thingsboard.entity_views | |
64 | + WHERE tenant_id IS NOT NULL | |
65 | + AND customer_id IS NOT NULL | |
66 | + AND entity_id IS NOT NULL | |
67 | + AND search_text IS NOT NULL | |
68 | + AND id IS NOT NULL | |
69 | + PRIMARY KEY (tenant_id, entity_id, search_text, id, customer_id) | |
70 | + WITH CLUSTERING ORDER BY (entity_id ASC, search_text ASC, id DESC, customer_id DESC); | |
59 | 71 | |
60 | -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer_and_search_text AS | |
61 | -SELECT * | |
62 | -from thingsboard.entity_views | |
63 | -WHERE entity_id IS NOT NULL AND search_text IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL | |
64 | -PRIMARY KEY (tenant_id, customer_id, search_text, id, entity_id) | |
65 | -WITH CLUSTERING ORDER BY (customer_id ASC, search_text ASC, id DESC, entity_id DESC); | |
72 | +CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer AS | |
73 | + SELECT * | |
74 | + from thingsboard.entity_views | |
75 | + WHERE tenant_id IS NOT NULL | |
76 | + AND customer_id IS NOT NULL | |
77 | + AND entity_id IS NOT NULL | |
78 | + AND search_text IS NOT NULL | |
79 | + AND id IS NOT NULL | |
80 | + PRIMARY KEY (tenant_id, customer_id, search_text, id, entity_id) | |
81 | + WITH CLUSTERING ORDER BY (customer_id DESC, search_text ASC, id DESC); | |
66 | 82 | |
67 | -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer_and_entity_and_search_text AS | |
68 | -SELECT * | |
69 | -from thingsboard.entity_views | |
70 | -WHERE entity_id IS NOT NULL AND search_text IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL | |
71 | -PRIMARY KEY (tenant_id, customer_id, search_text,entity_id, id) | |
72 | -WITH CLUSTERING ORDER BY (customer_id ASC, search_text ASC, entity_id DESC, id DESC); | |
83 | +CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer_and_entity AS | |
84 | + SELECT * | |
85 | + from thingsboard.entity_views | |
86 | + WHERE tenant_id IS NOT NULL | |
87 | + AND customer_id IS NOT NULL | |
88 | + AND entity_id IS NOT NULL | |
89 | + AND search_text IS NOT NULL | |
90 | + AND id IS NOT NULL | |
91 | + PRIMARY KEY (tenant_id, customer_id, entity_id, search_text, id) | |
92 | + WITH CLUSTERING ORDER BY (customer_id DESC, entity_id ASC, search_text ASC, id DESC); | ... | ... |
... | ... | @@ -150,15 +150,15 @@ public class ModelConstants { |
150 | 150 | public static final String ENTITY_VIEW_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY; |
151 | 151 | public static final String ENTITY_VIEW_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY; |
152 | 152 | public static final String ENTITY_VIEW_NAME_PROPERTY = DEVICE_NAME_PROPERTY; |
153 | - public static final String ENTITY_VIEW_BY_TENANT_AND_CUSTOMER_AND_ENTITY_AND_SEARCH_TEXT = "entity_views_by_tenant_and_customer_and_entity_and_search_text"; | |
154 | - public static final String ENTITY_VIEW_BY_TENANT_AND_CUSTOMER_AND_SEARCH_TEXT = "entity_views_by_tenant_and_customer_and_search_text"; | |
153 | + public static final String ENTITY_VIEW_BY_TENANT_AND_CUSTOMER_AND_ENTITY_AND_SEARCH_TEXT = "entity_views_by_tenant_and_customer_and_entity"; | |
154 | + public static final String ENTITY_VIEW_BY_TENANT_AND_CUSTOMER_AND_SEARCH_TEXT = "entity_views_by_tenant_and_customer"; | |
155 | 155 | public static final String ENTITY_VIEW_KEYS_PROPERTY = "keys"; |
156 | 156 | public static final String ENTITY_VIEW_START_TS_PROPERTY = "start_ts"; |
157 | 157 | public static final String ENTITY_VIEW_END_TS_PROPERTY = "end_ts"; |
158 | 158 | public static final String ENTITY_VIEW_ADDITIONAL_INFO_PROPERTY = ADDITIONAL_INFO_PROPERTY; |
159 | 159 | public static final String ENTITY_VIEW_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME = "entity_view_by_tenant_and_search_text"; |
160 | 160 | public static final String ENTITY_VIEW_BY_TENANT_AND_NAME = "entity_views_by_tenant_and_name"; |
161 | - public static final String ENTITY_VIEW_BY_TENANT_AND_ENTITY_AND_SEARCH_TEXT = "entity_view_by_tenant_and_entity_and_search_text"; | |
161 | + public static final String ENTITY_VIEW_BY_TENANT_AND_ENTITY_AND_SEARCH_TEXT = "entity_view_by_tenant_and_entity"; | |
162 | 162 | |
163 | 163 | /** |
164 | 164 | * Cassandra audit log constants. | ... | ... |
... | ... | @@ -165,35 +165,55 @@ CREATE TABLE IF NOT EXISTS thingsboard.device ( |
165 | 165 | CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_by_tenant_and_name AS |
166 | 166 | SELECT * |
167 | 167 | from thingsboard.device |
168 | - WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL | |
168 | + WHERE tenant_id IS NOT NULL | |
169 | + AND customer_id IS NOT NULL | |
170 | + AND type IS NOT NULL | |
171 | + AND name IS NOT NULL | |
172 | + AND id IS NOT NULL | |
169 | 173 | PRIMARY KEY ( tenant_id, name, id, customer_id, type) |
170 | 174 | WITH CLUSTERING ORDER BY ( name ASC, id DESC, customer_id DESC); |
171 | 175 | |
172 | 176 | CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_by_tenant_and_search_text AS |
173 | 177 | SELECT * |
174 | 178 | from thingsboard.device |
175 | - WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL | |
179 | + WHERE tenant_id IS NOT NULL | |
180 | + AND customer_id IS NOT NULL | |
181 | + AND type IS NOT NULL | |
182 | + AND search_text IS NOT NULL | |
183 | + AND id IS NOT NULL | |
176 | 184 | PRIMARY KEY ( tenant_id, search_text, id, customer_id, type) |
177 | 185 | WITH CLUSTERING ORDER BY ( search_text ASC, id DESC, customer_id DESC); |
178 | 186 | |
179 | 187 | CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_by_tenant_by_type_and_search_text AS |
180 | 188 | SELECT * |
181 | 189 | from thingsboard.device |
182 | - WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL | |
190 | + WHERE tenant_id IS NOT NULL | |
191 | + AND customer_id IS NOT NULL | |
192 | + AND type IS NOT NULL | |
193 | + AND search_text IS NOT NULL | |
194 | + AND id IS NOT NULL | |
183 | 195 | PRIMARY KEY ( tenant_id, type, search_text, id, customer_id) |
184 | 196 | WITH CLUSTERING ORDER BY ( type ASC, search_text ASC, id DESC, customer_id DESC); |
185 | 197 | |
186 | 198 | CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_by_customer_and_search_text AS |
187 | 199 | SELECT * |
188 | 200 | from thingsboard.device |
189 | - WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL | |
201 | + WHERE tenant_id IS NOT NULL | |
202 | + AND customer_id IS NOT NULL | |
203 | + AND type IS NOT NULL | |
204 | + AND search_text IS NOT NULL | |
205 | + AND id IS NOT NULL | |
190 | 206 | PRIMARY KEY ( customer_id, tenant_id, search_text, id, type ) |
191 | 207 | WITH CLUSTERING ORDER BY ( tenant_id DESC, search_text ASC, id DESC ); |
192 | 208 | |
193 | 209 | CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_by_customer_by_type_and_search_text AS |
194 | 210 | SELECT * |
195 | 211 | from thingsboard.device |
196 | - WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL | |
212 | + WHERE tenant_id IS NOT NULL | |
213 | + AND customer_id IS NOT NULL | |
214 | + AND type IS NOT NULL | |
215 | + AND search_text IS NOT NULL | |
216 | + AND id IS NOT NULL | |
197 | 217 | PRIMARY KEY ( customer_id, tenant_id, type, search_text, id ) |
198 | 218 | WITH CLUSTERING ORDER BY ( tenant_id DESC, type ASC, search_text ASC, id DESC ); |
199 | 219 | |
... | ... | @@ -651,40 +671,60 @@ CREATE TABLE IF NOT EXISTS thingsboard.entity_views ( |
651 | 671 | end_ts bigint, |
652 | 672 | search_text text, |
653 | 673 | additional_info text, |
654 | - PRIMARY KEY (id, tenant_id, customer_id) | |
674 | + PRIMARY KEY (id, entity_id, tenant_id, customer_id) | |
655 | 675 | ); |
656 | 676 | |
657 | 677 | CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_name AS |
658 | 678 | SELECT * |
659 | 679 | from thingsboard.entity_views |
660 | - WHERE entity_id IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL | |
661 | - PRIMARY KEY (tenant_id, name, id, entity_id, customer_id) | |
662 | - WITH CLUSTERING ORDER BY (name ASC, id DESC, entity_id DESC, customer_id DESC); | |
680 | + WHERE tenant_id IS NOT NULL | |
681 | + AND entity_id IS NOT NULL | |
682 | + AND customer_id IS NOT NULL | |
683 | + AND name IS NOT NULL | |
684 | + AND id IS NOT NULL | |
685 | + PRIMARY KEY (tenant_id, name, id, customer_id, entity_id) | |
686 | + WITH CLUSTERING ORDER BY (name ASC, id DESC, customer_id DESC); | |
663 | 687 | |
664 | 688 | CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_search_text AS |
665 | 689 | SELECT * |
666 | 690 | from thingsboard.entity_views |
667 | - WHERE entity_id IS NOT NULL AND search_text IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL | |
668 | - PRIMARY KEY (tenant_id, search_text, id, customer_id, name) | |
669 | - WITH CLUSTERING ORDER BY (search_text ASC, customer_id ASC, id DESC, name DESC); | |
670 | - | |
671 | -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_entity_and_search_text AS | |
691 | + WHERE tenant_id IS NOT NULL | |
692 | + AND entity_id IS NOT NULL | |
693 | + AND customer_id IS NOT NULL | |
694 | + AND search_text IS NOT NULL | |
695 | + AND id IS NOT NULL | |
696 | + PRIMARY KEY (tenant_id, search_text, id, customer_id, entity_id) | |
697 | + WITH CLUSTERING ORDER BY (search_text ASC, id DESC, customer_id DESC); | |
698 | + | |
699 | +CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_entity AS | |
672 | 700 | SELECT * |
673 | 701 | from thingsboard.entity_views |
674 | - WHERE entity_id IS NOT NULL AND search_text IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL | |
675 | - PRIMARY KEY (tenant_id, entity_id, search_text, id, customer_id, name) | |
676 | - WITH CLUSTERING ORDER BY (entity_id ASC, search_text ASC, id DESC, name DESC); | |
677 | - | |
678 | -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer_and_search_text AS | |
702 | + WHERE tenant_id IS NOT NULL | |
703 | + AND customer_id IS NOT NULL | |
704 | + AND entity_id IS NOT NULL | |
705 | + AND search_text IS NOT NULL | |
706 | + AND id IS NOT NULL | |
707 | + PRIMARY KEY (tenant_id, entity_id, search_text, id, customer_id) | |
708 | + WITH CLUSTERING ORDER BY (entity_id ASC, search_text ASC, id DESC, customer_id DESC); | |
709 | + | |
710 | +CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer AS | |
679 | 711 | SELECT * |
680 | 712 | from thingsboard.entity_views |
681 | - WHERE entity_id IS NOT NULL AND search_text IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL | |
713 | + WHERE tenant_id IS NOT NULL | |
714 | + AND customer_id IS NOT NULL | |
715 | + AND entity_id IS NOT NULL | |
716 | + AND search_text IS NOT NULL | |
717 | + AND id IS NOT NULL | |
682 | 718 | PRIMARY KEY (tenant_id, customer_id, search_text, id, entity_id) |
683 | - WITH CLUSTERING ORDER BY (customer_id ASC, search_text ASC, id DESC, entity_id DESC); | |
719 | + WITH CLUSTERING ORDER BY (customer_id DESC, search_text ASC, id DESC); | |
684 | 720 | |
685 | -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer_and_entity_and_search_text AS | |
721 | +CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer_and_entity AS | |
686 | 722 | SELECT * |
687 | 723 | from thingsboard.entity_views |
688 | - WHERE entity_id IS NOT NULL AND search_text IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL | |
689 | - PRIMARY KEY (tenant_id, customer_id, search_text,entity_id, id) | |
690 | - WITH CLUSTERING ORDER BY (customer_id ASC, search_text ASC, entity_id DESC, id DESC); | |
724 | + WHERE tenant_id IS NOT NULL | |
725 | + AND customer_id IS NOT NULL | |
726 | + AND entity_id IS NOT NULL | |
727 | + AND search_text IS NOT NULL | |
728 | + AND id IS NOT NULL | |
729 | + PRIMARY KEY (tenant_id, customer_id, entity_id, search_text, id) | |
730 | + WITH CLUSTERING ORDER BY (customer_id DESC, entity_id ASC, search_text ASC, id DESC); | ... | ... |