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

Function LogSortKeysCore

pg_documentdb/src/explain/documentdb_explain.c:1083–1125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1081
1082
1083static void
1084LogSortKeysCore(pgbson_writer *sortKeyWriter, Sort *plan, PlanState *leftTree,
1085 int startIndex, int numCols)
1086{
1087 for (int i = startIndex; i < startIndex + numCols; i++)
1088 {
1089 TargetEntry *entry = list_nth(plan->plan.targetlist, plan->sortColIdx[i] - 1);
1090
1091 Expr *entryExpr = entry->expr;
1092 if (IsA(entry->expr, Var) && leftTree != NULL)
1093 {
1094 Var *var = (Var *) entry->expr;
1095 if (list_length(leftTree->plan->targetlist) >= var->varattno)
1096 {
1097 TargetEntry *subTargetEntry = list_nth(leftTree->plan->targetlist,
1098 var->varattno - 1);
1099 entryExpr = subTargetEntry->expr;
1100 }
1101 }
1102
1103 if (IsA(entryExpr, FuncExpr))
1104 {
1105 FuncExpr *funcExpr = (FuncExpr *) entryExpr;
1106 if (funcExpr->funcid == BsonOrderByFunctionOid())
1107 {
1108 Expr *secondExpr = lsecond(funcExpr->args);
1109 if (IsA(secondExpr, Const))
1110 {
1111 Const *secondConst = (Const *) secondExpr;
1112 pgbson *orderBson = DatumGetPgBson(secondConst->constvalue);
1113 pgbsonelement sortElement;
1114 PgbsonToSinglePgbsonElementWithCollation(orderBson, &sortElement);
1115 PgbsonWriterAppendValue(sortKeyWriter, sortElement.path,
1116 sortElement.pathLength,
1117 &sortElement.bsonValue);
1118 continue;
1119 }
1120 }
1121 }
1122
1123 PgbsonWriterAppendInt32(sortKeyWriter, "unknown-sort-operator", -1, 0);
1124 }
1125}
1126
1127
1128static void

Callers 1

LogSortKeysFunction · 0.85

Tested by

no test coverage detected