| 1194 | |
| 1195 | |
| 1196 | static void |
| 1197 | WritePlanState(pgbson_writer *writer, const char *stageName, QueryDesc *queryDesc, |
| 1198 | PlanState *planState) |
| 1199 | { |
| 1200 | WriteMongoNamespaceName(writer, queryDesc, planState); |
| 1201 | |
| 1202 | PgbsonWriterAppendDouble(writer, "startupCost", -1, planState->plan->startup_cost); |
| 1203 | PgbsonWriterAppendDouble(writer, "totalCost", -1, planState->plan->total_cost); |
| 1204 | |
| 1205 | if (strcmp(stageName, "EOF") != 0) |
| 1206 | { |
| 1207 | /* For EOF stage, rows is always 0 and doesn't represent actual estimated rows, so we skip it to avoid confusion. */ |
| 1208 | PgbsonWriterAppendDouble(writer, "estimatedTotalKeysExamined", -1, |
| 1209 | planState->plan->plan_rows); |
| 1210 | } |
| 1211 | |
| 1212 | if (planState->plan->qual != NIL) |
| 1213 | { |
| 1214 | pgbson_writer qualWriter; |
| 1215 | PgbsonWriterStartDocument(writer, "filter", -1, &qualWriter); |
| 1216 | WriteQuals(&qualWriter, planState->plan->qual); |
| 1217 | PgbsonWriterEndDocument(writer, &qualWriter); |
| 1218 | } |
| 1219 | |
| 1220 | WriteProjectionState(planState, writer); |
| 1221 | |
| 1222 | /* per stage type planner output */ |
| 1223 | switch (nodeTag(planState->plan)) |
| 1224 | { |
| 1225 | case T_Limit: |
| 1226 | { |
| 1227 | LimitState *limitState = (LimitState *) planState; |
| 1228 | Limit *limitPlan = (Limit *) limitState->ps.plan; |
| 1229 | if (limitPlan->limitOffset != NULL && |
| 1230 | IsA(limitPlan->limitOffset, Const)) |
| 1231 | { |
| 1232 | Const *offsetConst = (Const *) limitPlan->limitOffset; |
| 1233 | PgbsonWriterAppendDouble(writer, "skipAmount", -1, DatumGetInt64( |
| 1234 | offsetConst->constvalue)); |
| 1235 | } |
| 1236 | |
| 1237 | if (limitPlan->limitCount != NULL && |
| 1238 | IsA(limitPlan->limitCount, Const)) |
| 1239 | { |
| 1240 | Const *countConst = (Const *) limitPlan->limitCount; |
| 1241 | PgbsonWriterAppendDouble(writer, "limitAmount", -1, DatumGetInt64( |
| 1242 | countConst->constvalue)); |
| 1243 | } |
| 1244 | |
| 1245 | break; |
| 1246 | } |
| 1247 | |
| 1248 | case T_IndexScan: |
| 1249 | { |
| 1250 | IndexScanState *indexScanState = (IndexScanState *) planState; |
| 1251 | IndexScan *plan = (IndexScan *) indexScanState->ss.ps.plan; |
| 1252 | |
| 1253 | LogIndexScanDetails(writer, plan->indexid, plan->indexorderdir, |
nothing calls this directly
no test coverage detected