* FindIndexWithSpecOptions searches for the index having given IndexSpec and * returns an IndexDetails object if it matches an index or NULL if there is * no such index. */
| 241 | * no such index. |
| 242 | */ |
| 243 | IndexDetails * |
| 244 | FindIndexWithSpecOptions(uint64 collectionId, const IndexSpec *targetIndexSpec) |
| 245 | { |
| 246 | const char *cmdStr = FormatSqlQuery( |
| 247 | "SELECT index_id, index_spec, %s.index_build_is_in_progress(index_id)" |
| 248 | "FROM %s.collection_indexes " |
| 249 | "WHERE collection_id = $1 AND %s.index_spec_options_are_equivalent(index_spec, $2) AND" |
| 250 | " (index_is_valid OR %s.index_build_is_in_progress(index_id))", |
| 251 | ApiInternalSchemaName, ApiCatalogSchemaName, |
| 252 | ApiInternalSchemaName, ApiInternalSchemaName); |
| 253 | |
| 254 | int argCount = 2; |
| 255 | Oid argTypes[2]; |
| 256 | Datum argValues[2]; |
| 257 | |
| 258 | argTypes[0] = INT8OID; |
| 259 | argValues[0] = UInt64GetDatum(collectionId); |
| 260 | |
| 261 | argTypes[1] = IndexSpecTypeId(); |
| 262 | argValues[1] = IndexSpecGetDatum(CopyIndexSpec(targetIndexSpec)); |
| 263 | |
| 264 | /* all args are non-null */ |
| 265 | char *argNulls = NULL; |
| 266 | |
| 267 | bool readOnly = true; |
| 268 | |
| 269 | int numValues = 3; |
| 270 | bool isNull[3]; |
| 271 | Datum results[3]; |
| 272 | ExtensionExecuteMultiValueQueryWithArgsViaSPI(cmdStr, argCount, argTypes, |
| 273 | argValues, argNulls, readOnly, |
| 274 | SPI_OK_SELECT, results, isNull, |
| 275 | numValues); |
| 276 | if (isNull[0]) |
| 277 | { |
| 278 | return NULL; |
| 279 | } |
| 280 | |
| 281 | IndexDetails *indexDetails = palloc0(sizeof(IndexDetails)); |
| 282 | indexDetails->indexId = DatumGetInt32(results[0]); |
| 283 | indexDetails->indexSpec = *DatumGetIndexSpec(results[1]); |
| 284 | indexDetails->collectionId = collectionId; |
| 285 | indexDetails->isIndexBuildInProgress = DatumGetBool(results[2]); |
| 286 | |
| 287 | return indexDetails; |
| 288 | } |
| 289 | |
| 290 | |
| 291 | /* |
no test coverage detected