Return-Path: pg_adm@postgres.berkeley.edu
Received: by postgres.Berkeley.EDU (5.61/1.29)
	id AA24486; Thu, 15 Jul 93 06:15:52 -0700
Message-Id: <9307151315.AA24486@postgres.Berkeley.EDU>
From: Wolf Guddat <guddat@faps.uni-erlangen.de>
Subject: postquel vi userfunct
To: postgres@postgres.berkeley.edu
Sender: pg_adm@postgres.berkeley.edu
To: postgres@postgres.berkeley.edu
Date: Thu, 15 Jul 93 15:24:25 MESZ
Cc: post-questions@postgres.berkeley.edu
Mailer: Elm [revision: 70.30]

Hi Everybody,

Once again because i haven't heard from you.

It's again about making postquel-queries from inside of user defined functions
which are dynamically loaded into the backend.

I have written a single really short function "eval" which accepts an int4 
and returns an int4.
Inside of this function i'm doing a PQexec (i call the routine pqtest_PQexec
from the file .../src/backend/libpq/be-pqexec.c which itself calls PQexec).
I'm compiling my routine the same way as all my other dynamic-functions, that
means WITHOUT binding LIBPQ.

I'm able to run the following monitor command several times:
      append J (j = eval (12))
where J is a class created by 
      create J (j=int4)
The class is populated correctly.
But after a few of these appends the monitor exits with
      Query sent to backend is "append J (j= eval(1234))"
      Error: Unexpected identifier in process_portal:

What i have figured out is that everytime i call pqtest_PQexec there are
more and more open portals (i think they are limited up to MAXPORTALS==10, have
read this somewhere in the source code)

Have you got an idea what is going wrong (or what i'm doing wrong)?

****************************************************
**                                                **
** Wolf Guddat, guddat@faber.faps.uni-erlangen.de **
**                                                **
**     Postgres 4.1, DECstation, ULTRIX 4.3       **
**                                                **
****************************************************

Following: my code
	   my printfs
	   core dump


******************************
******************************
MY C-CODE OF EVAL
******************************
******************************

#include <stdio.h>
#include "postgres.h"
#include "palloc.h"
#include "builtins.h"
#include "libpq-be.h"

#define EF "/user/sonst/wfguddat/XPR2PG/eval.err"

extern char *PQexec ();
extern PortalBuffer *PQparray ();
extern int PQntuplesGroup ();
extern int PQnfieldsGroup ();
extern char *PQfnameGroup ();
extern char *PQgetvalue ();
extern int PQnportals ();
extern void PQclear ();

int4 *eval (arg)
  int4 *arg;
{
  
  int n, rule_p;

FILE *ef;

ef = fopen (EF, "w");
fprintf (ef, "eval:\n");
fprintf (ef, "arg is [%d]\n", arg);

  rule_p = 1;
  n = PQnportals (rule_p);
fprintf (ef, "Number of open portals (%d)\n", n);

  n = pqtest_PQexec ("retrieve (I.all)");
fprintf (ef, "number of tuples returnd by pqtest_PQexec [%d]\n", n);

  n = PQnportals (rule_p);
fprintf (ef, "Number of open portals (%d)\n", n);
fclose (ef);

  return (arg);

} /* eval */




******************************
******************************
MY PRINTFS
******************************
******************************

eval:
arg is [12]
Number of open portals (0)
number of tuples returnd by pqtest_PQexec [7]
Number of open portals (0)
eval:
arg is [12]
Number of open portals (0)
number of tuples returnd by pqtest_PQexec [7]
Number of open portals (0)
eval:
arg is [12]
Number of open portals (0)
number of tuples returnd by pqtest_PQexec [7]
Number of open portals (2)
eval:
arg is [12]
Number of open portals (2)
number of tuples returnd by pqtest_PQexec [7]
Number of open portals (3)
eval:
arg is [12]
Number of open portals (3)
number of tuples returnd by pqtest_PQexec [7]
Number of open portals (4)


******************************
******************************
THE CORE DUMP
******************************
******************************
> dbx /usr/kits/postgres/bin/postmaster core
dbx version 2.10.1
Type 'help' for help.
Corefile produced from file "postgres"
Child died at pc 0x10048c64 of signal : Bus error
reading symbolic information ...
[using memory image in core]
(dbx) where
>  0 pqtest_PQfn(0x10176810, 0x10173044, 0x1000104c, 0x29cc2, 0x10024bd0) ["../access/common/../../libpq/be-pqexec.c":316, 0x10048c60]
   1 _equalParam(0x101a1190, 0x101a3250, 0x101a5350, 0x7fff99a8, 0x7fff9ac8) ["../access/common/../../lib/equalfuncs.c":282, 0x1003bca4]
   2 ExecProcNode(0x100b6d18, 0x7fff995c, 0x10001df4, 0x1019af24, 0x1019af10) ["../access/common/../../executor/ex_procnode.c":431, 0x10024bcc]
(dbx)

