* CollectionIdGetIndexNames returns names of the indexes that collection * with collectionId has. If 'inProgressOnly' flag is true, it returns * only the index names whose build is in progress. */
| 609 | * only the index names whose build is in progress. |
| 610 | */ |
| 611 | List * |
| 612 | CollectionIdGetIndexNames(uint64 collectionId, bool excludeIdIndex, bool inProgressOnly) |
| 613 | { |
| 614 | StringInfo cmdStr = makeStringInfo(); |
| 615 | appendStringInfo(cmdStr, |
| 616 | "SELECT array_agg((index_spec).index_name ORDER BY index_id) " |
| 617 | "FROM %s.collection_indexes WHERE collection_id = " UINT64_FORMAT, |
| 618 | ApiCatalogSchemaName, collectionId); |
| 619 | |
| 620 | if (inProgressOnly) |
| 621 | { |
| 622 | appendStringInfo(cmdStr, |
| 623 | " AND %s.index_build_is_in_progress(index_id)", |
| 624 | ApiInternalSchemaName); |
| 625 | } |
| 626 | else |
| 627 | { |
| 628 | appendStringInfo(cmdStr, |
| 629 | " AND (index_is_valid OR %s.index_build_is_in_progress(index_id))", |
| 630 | ApiInternalSchemaName); |
| 631 | } |
| 632 | |
| 633 | if (excludeIdIndex) |
| 634 | { |
| 635 | appendStringInfo(cmdStr, " AND (index_spec).index_name != %s", |
| 636 | quote_literal_cstr(ID_INDEX_NAME)); |
| 637 | } |
| 638 | |
| 639 | bool isNull = true; |
| 640 | bool readOnly = true; |
| 641 | Datum resultDatum = ExtensionExecuteQueryViaSPI(cmdStr->data, readOnly, |
| 642 | SPI_OK_SELECT, &isNull); |
| 643 | if (isNull) |
| 644 | { |
| 645 | /* This collection does not contain any indexes */ |
| 646 | return NIL; |
| 647 | } |
| 648 | |
| 649 | ArrayType *array = DatumGetArrayTypeP(resultDatum); |
| 650 | |
| 651 | /* error if any Datums are NULL */ |
| 652 | bool **nulls = NULL; |
| 653 | |
| 654 | Datum *elems = NULL; |
| 655 | int nelems = 0; |
| 656 | ArrayExtractDatums(array, TEXTOID, &elems, nulls, &nelems); |
| 657 | |
| 658 | List *indexNameList = NIL; |
| 659 | |
| 660 | for (int i = 0; i < nelems; i++) |
| 661 | { |
| 662 | indexNameList = lappend(indexNameList, TextDatumGetCString(elems[i])); |
| 663 | } |
| 664 | |
| 665 | return indexNameList; |
| 666 | } |
| 667 | |
| 668 |
no test coverage detected