* CollectionIdsGetIndexCount returns number of valid indexes that all the collections * in the given array collections has. * This function should be called at coordinator only as the index metadata table * is available on coordinator. */
| 846 | * is available on coordinator. |
| 847 | */ |
| 848 | int |
| 849 | CollectionIdsGetIndexCount(ArrayType *collectionIdsArray) |
| 850 | { |
| 851 | const char *query = |
| 852 | FormatSqlQuery("SELECT COUNT(*) FROM %s.collection_indexes " |
| 853 | "WHERE collection_id = ANY($1) AND (index_is_valid OR %s.index_build_is_in_progress(index_id))", |
| 854 | ApiCatalogSchemaName, ApiInternalSchemaName); |
| 855 | |
| 856 | int nargs = 1; |
| 857 | Oid argTypes[1] = { INT8ARRAYOID }; |
| 858 | Datum argValues[1] = { PointerGetDatum(collectionIdsArray) }; |
| 859 | |
| 860 | bool isReadOnly = true; |
| 861 | bool isNull = false; |
| 862 | Datum resultDatum = ExtensionExecuteQueryWithArgsViaSPI(query, nargs, argTypes, |
| 863 | argValues, |
| 864 | NULL, isReadOnly, |
| 865 | SPI_OK_SELECT, |
| 866 | &isNull); |
| 867 | |
| 868 | |
| 869 | Assert(!isNull); |
| 870 | if (DatumGetInt64(resultDatum) > INT_MAX) |
| 871 | { |
| 872 | ereport(ERROR, (errmsg("found too many indexes in index metadata"))); |
| 873 | } |
| 874 | |
| 875 | return DatumGetInt64(resultDatum); |
| 876 | } |
| 877 | |
| 878 | |
| 879 | /* |
no test coverage detected