MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / _Schema_RemoveExactMatchIndex

Function _Schema_RemoveExactMatchIndex

src/schema/schema.c:117–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115}
116
117static int _Schema_RemoveExactMatchIndex
118(
119 Schema *s,
120 const char *field
121) {
122 ASSERT(s != NULL);
123 ASSERT(field != NULL);
124
125 GraphContext *gc = QueryCtx_GetGraphCtx();
126
127 // convert attribute name to attribute ID
128 Attribute_ID attr_id = GraphContext_GetAttributeID(gc, field);
129 if(attr_id == ATTRIBUTE_ID_NONE) {
130 return INDEX_FAIL;
131 }
132
133 // try to get index
134 // if a pending index exists use it otherwise use the active index
135 Index active = ACTIVE_EXACTMATCH_IDX(s);
136 Index pending = PENDING_EXACTMATCH_IDX(s);
137 Index idx = pending;
138
139 // both pending and active indicies do not exists
140 if(pending == NULL) {
141 if(active == NULL) {
142 return INDEX_FAIL;
143 }
144 // use active
145 pending = Index_Clone(active);
146 PENDING_EXACTMATCH_IDX(s) = pending;
147 idx = pending;
148 }
149
150 // index doesn't containts attribute
151 if(Index_ContainsAttribute(idx, attr_id) == false) {
152 return INDEX_FAIL;
153 }
154
155 //--------------------------------------------------------------------------
156 // make sure index doesn't supports any constraints
157 //--------------------------------------------------------------------------
158
159 uint n = array_len(s->constraints);
160 for(uint i = 0; i < n; i++) {
161 Constraint c = s->constraints[i];
162 if(Constraint_GetStatus(c) != CT_FAILED &&
163 Constraint_GetType(c) == CT_UNIQUE &&
164 Constraint_ContainsAttribute(c, attr_id)) {
165 ErrorCtx_SetError("Index supports constraint");
166 return INDEX_FAIL;
167 }
168 }
169
170 Index_RemoveField(idx, attr_id);
171
172 // if index field count dropped to 0 remove index from schema
173 // index will be freed by the indexer thread
174 if(Index_FieldsCount(idx) == 0) {

Callers 1

Schema_RemoveIndexFunction · 0.85

Calls 13

QueryCtx_GetGraphCtxFunction · 0.85
Index_CloneFunction · 0.85
Index_ContainsAttributeFunction · 0.85
array_lenFunction · 0.85
Constraint_GetStatusFunction · 0.85
Constraint_GetTypeFunction · 0.85
ErrorCtx_SetErrorFunction · 0.85
Index_RemoveFieldFunction · 0.85
Index_FieldsCountFunction · 0.85
Indexer_DropIndexFunction · 0.85

Tested by

no test coverage detected