Index: src/backend/optimizer/prep/preptlist.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v retrieving revision 1.88 diff -c -r1.88 preptlist.c *** src/backend/optimizer/prep/preptlist.c 1 Jan 2008 19:45:50 -0000 1.88 --- src/backend/optimizer/prep/preptlist.c 30 Jan 2008 03:06:30 -0000 *************** *** 32,37 **** --- 32,38 ---- #include "optimizer/var.h" #include "parser/analyze.h" #include "parser/parsetree.h" + #include "parser/parse_clause.h" #include "parser/parse_coerce.h" *************** *** 103,108 **** --- 104,120 ---- tlist = list_copy(tlist); tlist = lappend(tlist, tle); + + /* + * Force the query result to be sorted by CTID, for better update + * speed. (Note: we expect parse->sortClause to be NIL here, + * but this code will do no harm if it's not.) + */ + parse->sortClause = addTargetToSortList(NULL, tle, + parse->sortClause, tlist, + SORTBY_DEFAULT, + SORTBY_NULLS_DEFAULT, + NIL, false); } /*