modifying the table function

Started by Islam Hegazyover 18 years ago5 messages
#1Islam Hegazy
islheg@gmail.com

Hi there

I made some changes in postgresql source code to let the table function work in iteration fashion rather than materialization fashion. My main modifications are in 'exec_simple_query' function, I changed 'portalRunSelect' to return just one tuple instead of 'FETCH_ALL'. I made other variables static as the 'portal', 'receiver', etc. so that the program returns to them to continue execution from the last point.
Then I added more calls to 'exec_simple_query' and it worked correctly. For example, if I added 4 calls to 'exec_simple_query' the 4th tuple is returned. My problem lies now in how to display the 1st, 2nd, 3rd tuples not just the 4th. I tried to call 'pq_flush' after each 'exec_simple_query' but nothing is displayed. I replaced 'pq_flush' with 'ReadyForQuery' but it gives the following error 'error 0x54 message received while system is idle'.

My question is how to inform the client that there is a tuple to display and return back to the backend to continue the query execution?

Regards
Islam Hegazy

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Islam Hegazy (#1)
Re: modifying the table function

"Islam Hegazy" <islheg@gmail.com> writes:

My question is how to inform the client that there is a tuple to display =
and return back to the backend to continue the query execution?

I'd suggest you start by reading
http://developer.postgresql.org/pgdocs/postgres/protocol.html
and then develop a clear specification at that level of what you
think should happen. Perhaps after that exercise it will be clearer
how to change the code. "Think first, program later."

regards, tom lane

#3Islam Hegazy
islheg@gmail.com
In reply to: Islam Hegazy (#1)
Re: modifying the table function

Thanks for the documentation link. It helped me to understand how data are
passed back to the client.

I figured out that data is sent back to the client using the 'printtup'
function. It is called by ExecSelect, called by ExecutorRun, etc. What I
understand now is that the data is sent to the client and stored there until
the client receives a message from the server to display it. The server
sends the display message from within 'ReadyForQuery' but I can't figure it
out.

What I expect is that when I call 'exec_simple_query' several times, the
server sends one row only for each call. But since they are separate calls,
the client overwrites the previous results or saves the new row in a new
place in memory such that it displays the last row only when the server
invokes 'ReadyForQuery'.

I wonder if I am on the right track or not and how to know such kind of
message sent from the server?

Regards
Islam Hegazy

----- Original Message -----
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "Islam Hegazy" <islheg@gmail.com>
Cc: <pgsql-hackers@postgresql.org>
Sent: Tuesday, April 17, 2007 1:44 AM
Subject: Re: [HACKERS] modifying the table function

Show quoted text

"Islam Hegazy" <islheg@gmail.com> writes:

My question is how to inform the client that there is a tuple to display
=
and return back to the backend to continue the query execution?

I'd suggest you start by reading
http://developer.postgresql.org/pgdocs/postgres/protocol.html
and then develop a clear specification at that level of what you
think should happen. Perhaps after that exercise it will be clearer
how to change the code. "Think first, program later."

regards, tom lane

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Islam Hegazy (#3)
Re: modifying the table function

"Islam Hegazy" <islheg@gmail.com> writes:

I wonder if I am on the right track or not and how to know such kind of
message sent from the server?

Seems like you're doing it the hard way. Wouldn't it be easier to fix
the client to display data before it's received the whole query result?

regards, tom lane

#5Islam Hegazy
islheg@gmail.com
In reply to: Islam Hegazy (#1)
Re: modifying the table function

Hi again

It seems now that I am one step away from the end. So far I have succeeded
in returing row by row from the backend to the frontend, knew this from
debugging.

Now comes the point of displaying them directly not to wait till the end of
the query. These are the steps I took:

1) redefined 'PrintQueryResults' in common.c to be extern (not static as the
initial definition) to be able to use it elsewhere
2) added a declaration for ''PrintQueryResults' in common.h, to tell other
files about it
3) removed 'PrintQueryResults' invocation from 'SendQuery' common.c
4) added #include "../bin/psql/common.h" to fe-exec.c
5) called 'PrintQueryResults' from within 'PQexecFinish', last statment in
the while loop

when I gmake the project I receive the following error:
"
../../../src/interfaces/libpq/libpq.so: undefined reference to
`PrintQueryTuples'
collect2: ld returned 1 exit status
gmake[3]: *** [initdb] Error 1
gmake[3]: Leaving directory
`/home/grads/imehegaz/postgresql-8.2.3-b/src/bin/initdb'
"

I wonder what does this error mean and how to solve it?

Regards
Islam Hegazy

----- Original Message -----
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "Islam Hegazy" <islheg@gmail.com>
Cc: <pgsql-hackers@postgresql.org>
Sent: Wednesday, April 18, 2007 6:38 PM
Subject: Re: [HACKERS] modifying the table function

Show quoted text

"Islam Hegazy" <islheg@gmail.com> writes:

I wonder if I am on the right track or not and how to know such kind of
message sent from the server?

Seems like you're doing it the hard way. Wouldn't it be easier to fix
the client to display data before it's received the whole query result?

regards, tom lane