diff -ruN 5.0/libmysqld/Makefile.am 5.0-myproc/libmysqld/Makefile.am
--- 5.0/libmysqld/Makefile.am	2007-08-09 12:18:16.000000000 +0200
+++ 5.0-myproc/libmysqld/Makefile.am	2007-08-09 00:21:55.000000000 +0200
@@ -54,6 +54,7 @@
 	opt_sum.cc procedure.cc records.cc sql_acl.cc \
 	sql_load.cc discover.cc sql_locale.cc \
 	sql_analyse.cc sql_base.cc sql_cache.cc sql_class.cc \
+	procedure_rownum.cc \
 	sql_crypt.cc sql_db.cc sql_delete.cc sql_error.cc sql_insert.cc \
 	sql_lex.cc sql_list.cc sql_manager.cc sql_map.cc sql_parse.cc \
 	sql_prepare.cc sql_derived.cc sql_rename.cc \
diff -ruN 5.0/sql/Makefile.am 5.0-myproc/sql/Makefile.am
--- 5.0/sql/Makefile.am	2007-08-09 12:11:16.000000000 +0200
+++ 5.0-myproc/sql/Makefile.am	2007-08-09 00:22:19.000000000 +0200
@@ -94,6 +94,7 @@
 			sql_db.cc sql_table.cc sql_rename.cc sql_crypt.cc \
 			sql_load.cc mf_iocache.cc field_conv.cc sql_show.cc \
 			sql_udf.cc sql_analyse.cc sql_analyse.h sql_cache.cc \
+			procedure_rownum.cc procedure_rownum.h \
 			slave.cc sql_repl.cc sql_union.cc sql_derived.cc \
 			client.c sql_client.cc mini_client_errors.c pack.c\
 			stacktrace.c repl_failsafe.h repl_failsafe.cc \
diff -ruN 5.0/sql/procedure.cc 5.0-myproc/sql/procedure.cc
--- 5.0/sql/procedure.cc	2007-08-09 12:11:16.000000000 +0200
+++ 5.0-myproc/sql/procedure.cc	2007-08-09 00:21:04.000000000 +0200
@@ -23,6 +23,7 @@
 #include "mysql_priv.h"
 #include "procedure.h"
 #include "sql_analyse.h"			// Includes procedure
+#include "procedure_rownum.h"		// Includes procedure
 #ifdef USE_PROC_RANGE
 #include "proc_range.h"
 #endif
@@ -37,6 +38,7 @@
   { "split_count",proc_count_range_init },	// Internal procedure at TCX
   { "matris_ranges",proc_matris_range_init },	// Internal procedure at TCX
 #endif
+  { "rownum", proc_rownum_init }, 		// Add RowNum column to result
   { "analyse",proc_analyse_init }		// Analyse a result
 };
 
diff -ruN 5.0/sql/procedure_rownum.cc 5.0-myproc/sql/procedure_rownum.cc
--- 5.0/sql/procedure_rownum.cc	1970-01-01 01:00:00.000000000 +0100
+++ 5.0-myproc/sql/procedure_rownum.cc	2007-08-09 00:18:37.000000000 +0200
@@ -0,0 +1,95 @@
+/* Copyright (C) 2000-2006 MySQL AB
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
+
+/* procedure that adds a RowNum column to any result */
+
+#ifdef USE_PRAGMA_IMPLEMENTATION
+#pragma implementation				// gcc: Class implementation
+#endif
+
+#include "mysql_priv.h"
+#include "procedure.h"
+
+#include "procedure_rownum.h"
+
+// Create and register the actual procedure object
+Procedure *proc_rownum_init(THD *thd, ORDER *param,
+							select_result *result,
+							List<Item> &field_list) 
+{
+  DBUG_ENTER("proc_rownum_init");
+
+  proc_rownum *pc = new proc_rownum(result);
+
+  DBUG_RETURN(pc);
+}
+
+// modify the result set column types here
+bool proc_rownum::change_columns(List<Item> &field_list)
+{
+  DBUG_ENTER("proc_rownum::change_columns");
+
+  // create a new column item
+  row_num_column = new Item_proc_int("RowNum");
+
+  // and attach it to the column list
+  field_list.push_back(row_num_column);
+
+  DBUG_RETURN(0);
+}
+
+// not used here and not in ANALYSE() either,
+// probably called for each row before grouping
+void proc_rownum::add(void)
+{
+  DBUG_ENTER("proc_rownum::add");
+
+  DBUG_VOID_RETURN;
+}
+
+// not used here and not in ANALYSE() either,
+// probably called whenever a group rows were fully processed 
+void proc_rownum::end_group(void)
+{
+  DBUG_ENTER("proc_rownum::end_group");
+
+  DBUG_VOID_RETURN;
+}
+
+// called before sending result rows, you may modify the results here
+int proc_rownum::send_row(List<Item> &field_list __attribute__((unused)))
+{
+  DBUG_ENTER("proc_rownum::send_row");
+
+  // increment row count and set its new value in result row
+  row_num_column->set(++row_num);
+
+  // now send the modified results
+  if (result->send_data(field_list))
+	DBUG_RETURN(-1);
+
+  DBUG_RETURN(0);
+}
+
+// called after sending all result rows, 
+// you may add summary rows here as ANALYSE() does
+bool proc_rownum::end_of_records(void)
+{
+  DBUG_ENTER("proc_rownum::end_of_records");
+
+  DBUG_RETURN(0);
+}
+
diff -ruN 5.0/sql/procedure_rownum.h 5.0-myproc/sql/procedure_rownum.h
--- 5.0/sql/procedure_rownum.h	1970-01-01 01:00:00.000000000 +0100
+++ 5.0-myproc/sql/procedure_rownum.h	2007-08-09 00:19:08.000000000 +0200
@@ -0,0 +1,55 @@
+/* Copyright (C) 2000-2006 MySQL AB
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
+
+/* procedure that adds a RowNum column to any result */
+
+#ifdef USE_PRAGMA_INTERFACE
+#pragma interface				/* gcc class implementation */
+#endif
+
+#ifndef PROCEDURE_ROWNUM_H
+#define PROCEDURE_ROWNUM_H
+
+Procedure *proc_rownum_init(THD *thd, ORDER *param,
+			     select_result *result,
+			     List<Item> &field_list);
+
+
+class proc_rownum: public Procedure
+{
+protected:
+  Item_proc *row_num_column;
+  longlong  row_num;
+
+public:
+  proc_rownum(select_result *res) :Procedure(res, PROC_NO_SORT), row_num(0)
+  {}
+
+  ~proc_rownum()
+  {}
+
+  virtual void add(void);
+  virtual bool change_columns(List<Item> &fields);
+  virtual int  send_row(List<Item> &fields);
+  virtual void end_group(void);
+  virtual bool end_of_records(void);
+
+  friend Procedure *proc_rownum_init(THD *thd, ORDER *param,
+				      select_result *result,
+				      List<Item> &field_list);
+};
+
+#endif
