MCPcopy Create free account
hub / github.com/documentdb/documentdb / IndexSpecOptionsAreEquivalent

Function IndexSpecOptionsAreEquivalent

pg_documentdb/src/metadata/index.c:361–485  ·  view source on GitHub ↗

* IndexSpecOptionsAreEquivalent returns true given two IndexSpec's are * equivalent except their index names and expireAfterSeconds options. * * We don't check them because they should anyway be the same for two indexes * as long as all the other options are the same. * If it's exactly the same it returns IndexOptionsEquivalency_Equal. * If they're not exactly the same, but can still be trea

Source from the content-addressed store, hash-verified

359 * otherwise returns IndexOptionsEquivalency_NotEquivalent.
360 */
361IndexOptionsEquivalency
362IndexSpecOptionsAreEquivalent(const IndexSpec *leftIndexSpec,
363 const IndexSpec *rightIndexSpec)
364{
365 if (leftIndexSpec->indexVersion != rightIndexSpec->indexVersion)
366 {
367 return IndexOptionsEquivalency_NotEquivalent;
368 }
369
370 bool sparseMatches = (leftIndexSpec->indexSparse == BoolIndexOption_True) ==
371 (rightIndexSpec->indexSparse == BoolIndexOption_True);
372 if (!sparseMatches)
373 {
374 return IndexOptionsEquivalency_NotEquivalent;
375 }
376
377 bool uniqueMatches = (leftIndexSpec->indexUnique == BoolIndexOption_True) ==
378 (rightIndexSpec->indexUnique == BoolIndexOption_True);
379 if (!uniqueMatches)
380 {
381 return IndexOptionsEquivalency_NotEquivalent;
382 }
383
384 IndexOptionsEquivalency equivalency = IndexKeyDocumentEquivalent(
385 leftIndexSpec->indexKeyDocument,
386 rightIndexSpec->indexKeyDocument);
387 if (equivalency == IndexOptionsEquivalency_NotEquivalent ||
388 equivalency == IndexOptionsEquivalency_TextEquivalent)
389 {
390 return equivalency;
391 }
392
393 if (leftIndexSpec->indexWPDocument == NULL &&
394 rightIndexSpec->indexWPDocument == NULL)
395 {
396 /* both are NULL, check for other options */
397 }
398 else if (leftIndexSpec->indexWPDocument == NULL ||
399 rightIndexSpec->indexWPDocument == NULL)
400 {
401 /* one of them is NULL but not the other */
402 return IndexOptionsEquivalency_NotEquivalent;
403 }
404 else if (!WildcardProjDocsAreEquivalent(leftIndexSpec->indexWPDocument,
405 rightIndexSpec->indexWPDocument))
406 {
407 return IndexOptionsEquivalency_NotEquivalent;
408 }
409
410 bool convertSupportedInToScalarArrayOp = true;
411 if (leftIndexSpec->indexPFEDocument == NULL &&
412 rightIndexSpec->indexPFEDocument == NULL)
413 {
414 /* both are NULL, check for other options */
415 }
416 else if (leftIndexSpec->indexPFEDocument == NULL ||
417 rightIndexSpec->indexPFEDocument == NULL)
418 {

Tested by

no test coverage detected