| 989 | |
| 990 | |
| 991 | static void |
| 992 | WriteIndexOrderBy(pgbson_writer *writer, List *indexOrderBy, Oid indexAm, ScanDirection |
| 993 | indexorderdir) |
| 994 | { |
| 995 | ListCell *orderByCell; |
| 996 | foreach(orderByCell, indexOrderBy) |
| 997 | { |
| 998 | Expr *indexOrder = (Expr *) lfirst(orderByCell); |
| 999 | |
| 1000 | if (IsA(indexOrder, Var) && indexAm == BTREE_AM_OID) |
| 1001 | { |
| 1002 | /* order by could by by object_id */ |
| 1003 | Var *var = (Var *) indexOrder; |
| 1004 | if (var->varno == INDEX_VAR && |
| 1005 | var->varattno == DOCUMENT_DATA_TABLE_OBJECT_ID_VAR_ATTR_NUMBER) |
| 1006 | { |
| 1007 | PgbsonWriterAppendInt32(writer, "_id", 3, ScanDirectionIsForward( |
| 1008 | indexorderdir) ? 1 : -1); |
| 1009 | } |
| 1010 | } |
| 1011 | else if (IsA(indexOrder, OpExpr)) |
| 1012 | { |
| 1013 | OpExpr *opExpr = (OpExpr *) indexOrder; |
| 1014 | if (opExpr->opno == BsonOrderByIndexOperatorId() || |
| 1015 | opExpr->opno == BsonOrderByReverseIndexOperatorId()) |
| 1016 | { |
| 1017 | Expr *orderArg = lsecond(opExpr->args); |
| 1018 | if (IsA(orderArg, Const)) |
| 1019 | { |
| 1020 | Const *orderConst = (Const *) orderArg; |
| 1021 | pgbsonelement orderElement; |
| 1022 | PgbsonToSinglePgbsonElementWithCollation(DatumGetPgBson( |
| 1023 | orderConst->constvalue), |
| 1024 | &orderElement); |
| 1025 | PgbsonWriterAppendValue(writer, orderElement.path, |
| 1026 | orderElement.pathLength, |
| 1027 | &orderElement.bsonValue); |
| 1028 | } |
| 1029 | } |
| 1030 | } |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | |
| 1035 | static void |
no test coverage detected