| 115 | } |
| 116 | |
| 117 | static 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) { |
no test coverage detected