diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c new file mode 100644 index 25839ee..522d8e1 *** a/src/backend/nodes/copyfuncs.c --- b/src/backend/nodes/copyfuncs.c *************** static IndexScan * *** 367,372 **** --- 367,373 ---- _copyIndexScan(const IndexScan *from) { IndexScan *newnode = makeNode(IndexScan); + int numOrderbys; /* * copy node superclass fields *************** _copyIndexScan(const IndexScan *from) *** 381,386 **** --- 382,390 ---- COPY_NODE_FIELD(indexqualorig); COPY_NODE_FIELD(indexorderby); COPY_NODE_FIELD(indexorderbyorig); + numOrderbys = list_length(from->indexorderby); + if (numOrderbys > 0) + COPY_POINTER_FIELD(indexorderbyops, numOrderbys * sizeof(Oid)); COPY_SCALAR_FIELD(indexorderdir); return newnode; diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c new file mode 100644 index fe868b8..9b71d2b *** a/src/backend/nodes/outfuncs.c --- b/src/backend/nodes/outfuncs.c *************** _outSeqScan(StringInfo str, const SeqSca *** 448,453 **** --- 448,455 ---- static void _outIndexScan(StringInfo str, const IndexScan *node) { + int numOrderbys, i; + WRITE_NODE_TYPE("INDEXSCAN"); _outScanInfo(str, (const Scan *) node); *************** _outIndexScan(StringInfo str, const Inde *** 457,462 **** --- 459,471 ---- WRITE_NODE_FIELD(indexqualorig); WRITE_NODE_FIELD(indexorderby); WRITE_NODE_FIELD(indexorderbyorig); + + numOrderbys = list_length(node->indexorderby); + appendStringInfoString(str, " :indexorderbyops"); + for (i = 0; i < numOrderbys; i++) + appendStringInfo(str, " %u", node->indexorderbyops[i]); + + WRITE_NODE_FIELD(indexorderby); WRITE_ENUM_FIELD(indexorderdir, ScanDirection); } diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c new file mode 100644 index 783e34b..1b28b4b *** a/src/backend/optimizer/plan/createplan.c --- b/src/backend/optimizer/plan/createplan.c *************** create_indexscan_plan(PlannerInfo *root, *** 1275,1281 **** * If there are ORDER BY expressions, look up the sort operators for * their datatypes. */ ! if (best_path->path.pathkeys && indexorderbys) { int numOrderBys = list_length(indexorderbys); int i; --- 1275,1281 ---- * If there are ORDER BY expressions, look up the sort operators for * their datatypes. */ ! if (indexorderbys) { int numOrderBys = list_length(indexorderbys); int i; *************** create_indexscan_plan(PlannerInfo *root, *** 1285,1290 **** --- 1285,1293 ---- Expr *expr; EquivalenceMember *em; + /* indexorderbys should present only simultaneously with pathkeys */ + Assert(best_path->path.pathkeys); + indexorderbyops = (Oid *) palloc(numOrderBys * sizeof(Oid)); /*