Re: Trying to compute the median

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Maciej Bliziński <maciej(dot)blizinski(at)dobranet(dot)polbox(dot)pl>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Trying to compute the median
Date: 2004-05-11 13:22:43
Message-ID: 8854.1084281763@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Maciej =?iso-8859-2?Q?Blizi=F1ski?= <maciej(dot)blizinski(at)dobranet(dot)polbox(dot)pl> writes:
> I started to write the query that should compute the median.
> Surprisingly, I get following error message:
> "server closed the connection unexpectedly

Yeah, that's a bug. The patch is attached if you need it. However, I
think you will wind up looking for some other way to solve the problem,
because this query won't scale well to large datasets.

regards, tom lane

Index: setrefs.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/optimizer/plan/setrefs.c,v
retrieving revision 1.97
diff -c -r1.97 setrefs.c
*** setrefs.c 8 Aug 2003 21:41:50 -0000 1.97
--- setrefs.c 11 May 2004 12:45:54 -0000
***************
*** 189,195 ****
case T_Sort:
case T_Unique:
case T_SetOp:
- case T_Limit:

/*
* These plan types don't actually bother to evaluate their
--- 189,194 ----
***************
*** 201,206 ****
--- 200,214 ----
* reprocessing subplans that also appear in lower levels of
* the plan tree!
*/
+ break;
+ case T_Limit:
+ /*
+ * Like the plan types above, Limit doesn't evaluate its
+ * tlist or quals. It does have live expressions for
+ * limit/offset, however.
+ */
+ fix_expr_references(plan, ((Limit *) plan)->limitOffset);
+ fix_expr_references(plan, ((Limit *) plan)->limitCount);
break;
case T_Agg:
case T_Group:
Index: subselect.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/optimizer/plan/subselect.c,v
retrieving revision 1.83.2.1
diff -c -r1.83.2.1 subselect.c
*** subselect.c 25 Nov 2003 23:59:32 -0000 1.83.2.1
--- subselect.c 11 May 2004 12:45:54 -0000
***************
*** 1018,1023 ****
--- 1018,1030 ----
&context);
break;

+ case T_Limit:
+ finalize_primnode(((Limit *) plan)->limitOffset,
+ &context);
+ finalize_primnode(((Limit *) plan)->limitCount,
+ &context);
+ break;
+
case T_Hash:
finalize_primnode((Node *) ((Hash *) plan)->hashkeys,
&context);
***************
*** 1029,1035 ****
case T_Sort:
case T_Unique:
case T_SetOp:
- case T_Limit:
case T_Group:
break;

--- 1036,1041 ----

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2004-05-11 13:44:26 Re: Adding MERGE to the TODO list (resend with subject)
Previous Message Tom Lane 2004-05-11 11:54:34 Re: Very slow query