get index from schema returns NULL if index wasn't found
| 396 | // get index from schema |
| 397 | // returns NULL if index wasn't found |
| 398 | Index Schema_GetIndex |
| 399 | ( |
| 400 | const Schema *s, // schema to get index from |
| 401 | const Attribute_ID *attrs, // indexed attributes |
| 402 | uint n, // number of attributes |
| 403 | IndexType type, // type of index |
| 404 | bool include_pending // take into considiration pending indicies |
| 405 | ) { |
| 406 | // validations |
| 407 | ASSERT(s != NULL); |
| 408 | ASSERT((attrs == NULL && n == 0) || (attrs != NULL && n > 0)); |
| 409 | |
| 410 | Index idx = NULL; // index to return |
| 411 | uint idx_count = 1; // number of indicies to consider |
| 412 | Index indicies[4] = {0}; // indicies to consider |
| 413 | |
| 414 | if(type != IDX_ANY) { |
| 415 | // consider specified index |
| 416 | if(include_pending) idx_count = 2; |
| 417 | if(type == IDX_FULLTEXT) { |
| 418 | indicies[0] = ACTIVE_FULLTEXT_IDX(s); |
| 419 | if(include_pending) indicies[1] = PENDING_FULLTEXT_IDX(s); |
| 420 | } else { |
| 421 | indicies[0] = ACTIVE_EXACTMATCH_IDX(s); |
| 422 | if(include_pending) indicies[1] = PENDING_EXACTMATCH_IDX(s); |
| 423 | } |
| 424 | } else { |
| 425 | idx_count = 2; |
| 426 | indicies[0] = ACTIVE_EXACTMATCH_IDX(s); |
| 427 | indicies[1] = ACTIVE_FULLTEXT_IDX(s); |
| 428 | if(include_pending) { |
| 429 | // consider all indicies exact-match and fulltext indicies |
| 430 | idx_count = 4; |
| 431 | indicies[2] = PENDING_EXACTMATCH_IDX(s); |
| 432 | indicies[3] = PENDING_FULLTEXT_IDX(s); |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | //-------------------------------------------------------------------------- |
| 437 | // return first index which contains all specified attributes |
| 438 | //-------------------------------------------------------------------------- |
| 439 | |
| 440 | for(uint i = 0; i < idx_count; i++) { |
| 441 | idx = indicies[i]; |
| 442 | |
| 443 | // index doesn't exists |
| 444 | if(idx == NULL) { |
| 445 | continue; |
| 446 | } |
| 447 | |
| 448 | // make sure index contains all specified attributes |
| 449 | bool all_attr_found = true; |
| 450 | for(uint i = 0; i < n; i++) { |
| 451 | if(!Index_ContainsAttribute(idx, attrs[i])) { |
| 452 | idx = NULL; |
| 453 | all_attr_found = false; |
| 454 | break; |
| 455 | } |
no test coverage detected