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

Function GenerateIndexExprStr

pg_documentdb/src/commands/create_indexes.c:5748–6356  ·  view source on GitHub ↗

* GenerateIndexExprStr returns column expression string to be used when * creating the index whose "key" and "wildcardProjection" specifications * are determined by given objects. * * indexDefWildcardProjTree should be passed to be NULL if index doesn't * have a "wildcardProjection" specification. */

Source from the content-addressed store, hash-verified

5746 * have a "wildcardProjection" specification.
5747 */
5748static char *
5749GenerateIndexExprStr(const char *indexAmSuffix,
5750 bool unique, bool buildAsUnique, bool sparse,
5751 bool enableCompositeOpClass,
5752 IndexDefKey *indexDefKey,
5753 const BsonIntermediatePathNode *indexDefWildcardProjTree,
5754 const char *indexName, const char *defaultLanguage,
5755 const char *languageOverride, bool enableLargeIndexKeys,
5756 bool useReducedWildcardTerms,
5757 const char *indexAmOpClassCatalogSchema,
5758 const char *indexAmOpClassInternalCatalogSchema,
5759 const char *collationString)
5760{
5761 StringInfo indexExprStr = makeStringInfo();
5762
5763 char *languageOptionKey = "";
5764 char *languageOptionValue = "";
5765 char *languageOverrideKey = "";
5766 char *languageOverrideValue = "";
5767 if (defaultLanguage != NULL)
5768 {
5769 languageOptionKey = ",defaultlanguage=";
5770 languageOptionValue = quote_literal_cstr(defaultLanguage);
5771 }
5772
5773 if (languageOverride != NULL)
5774 {
5775 languageOverrideKey = ",languageOverride=";
5776 languageOverrideValue = quote_literal_cstr(languageOverride);
5777 }
5778
5779 bool firstColumnWritten = false;
5780 char indexTermSizeLimitArg[22] = { 0 };
5781 bool enableTruncation = enableLargeIndexKeys || ForceIndexTermTruncation;
5782
5783 bool isUsingCompositeOpClass = enableCompositeOpClass &&
5784 indexDefKey->canSupportCompositeTerm;
5785 bool usingNewUniqueIndexOpClass = (unique || buildAsUnique) &&
5786 (enableLargeIndexKeys ||
5787 isUsingCompositeOpClass);
5788
5789 bool hasApplicableCollation = IsCollationValid(collationString);
5790 char *collationArg = "";
5791 if (hasApplicableCollation)
5792 {
5793 StringInfo collationArgStr = makeStringInfo();
5794 appendStringInfo(collationArgStr, ",cl=%s",
5795 quote_literal_cstr(collationString));
5796 collationArg = collationArgStr->data;
5797 }
5798
5799 /* For unique with truncation, instead of creating a unique hash for every column, we simply create a single
5800 * value with a new operator that handles unique constraints. That way for a composite unique index, we support
5801 * up to 31 columns (instead of 16 without truncation). Here we want to produce a term that incorporates the
5802 * shard key as well as the document term such that we produce something that is relatively collision resistant
5803 * This would avoid runtime rechecks for uniqueness.
5804 * For composite, this is written at the end: This is because the query path and order by is simpler if the composite
5805 * is the first path instead of the second. The unique column is only ever used for deduping unique and doing the runtime

Callers 1

Calls 15

IsCollationValidFunction · 0.85
AppendUniqueColumnExprFunction · 0.85
ComputeIndexTermLimitFunction · 0.85
SerializeWeightedPathsFunction · 0.85
ResolveWPPathOpsFromTreeFunction · 0.85
PgbsonWriterInitFunction · 0.85
PgbsonWriterStartArrayFunction · 0.85
PgbsonWriterAppendInt32Function · 0.85

Tested by

no test coverage detected