pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feed\d tablename with psql over slow links...
5+ messages / 3 participants
[nested] [flat]
* \d tablename with psql over slow links...
@ 2003-02-23 16:37 mallah@trade-india.com
2003-02-23 16:58 ` Re: \d tablename with psql over slow links... Tom Lane <tgl@sss.pgh.pa.us>
2003-02-24 03:55 ` Re: \d tablename with psql over slow links... Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 2 replies; 5+ messages in thread
From: mallah@trade-india.com @ 2003-02-23 16:37 UTC (permalink / raw)
To: pgsql-admin
Hi.
The \d tablename is too slow when its comes to usage over a dialup connection.
What i observed is that psql issues a sperate set of sql for getting default
value of each attribute if it has. The number sqls increases as the
size of table increases (no of attributes).
the information abt the default values can also be got by using a subselect
in the top level query which psql does to get list of attributes.
over local/fast links it may not be significant problem , but for dial up
connections it does.
I observed that a table which used to take 16 secs with \d was only taking
6 secs if the query for default attribute values are shifted to top level query in
psql/describe.c ( function describeOneTableDetails ) .
below is the diff for describe.c
Any comments?
[root@subho psql]# diff -B ../safepsql/describe.c describe.c
638a639
> unsigned int defaultcol = 5;
706a709,714
>
> /* my code additions 1 */
> appendPQExpBuffer(&buf, ", (SELECT substring(adsrc for 128) FROM pg_catalog.pg_attrdef
> WHERE adrelid =%s AND adnum = a.attnum ) " , oid );> /* ends 1 */
>
>
760,768d775
< PGresult *result;
<
< printfPQExpBuffer(&buf,
< "SELECT substring(d.adsrc for
128) FROM pg_catalog.pg_attrdef d\n"< "WHERE d.adrelid = '%s' AND d.adnum = %s",
< oid, PQgetvalue(res, i, 4));
<
< result = PSQLexec(buf.data, false);
<
772d779
< strcat(cells[i * cols + 2], result ? PQgetvalue(result, 0, 0) : "?");
774c781,784
< PQclear(result);
---
> if (verbose)
> defaultcol = 6;
> strcat(cells[i * cols + 2], PQgetvalue(res, i, defaultcol ) );
>
-----------------------------------------
Get your free web based email at trade-india.com.
"India's Leading B2B eMarketplace.!"
http://www.trade-india.com/
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: \d tablename with psql over slow links...
2003-02-23 16:37 \d tablename with psql over slow links... mallah@trade-india.com
@ 2003-02-23 16:58 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-02-24 03:13 ` Re: \d tablename with psql over slow links... mallah@trade-india.com
1 sibling, 1 reply; 5+ messages in thread
From: Tom Lane @ 2003-02-23 16:58 UTC (permalink / raw)
To: mallah@trade-india.com; +Cc: pgsql-admin
<mallah@trade-india.com> writes:
> below is the diff for describe.c
"diff -c" please. Without context a diff is essentially worthless,
since your version of the input file is unlikely to match development
sources.
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: \d tablename with psql over slow links...
2003-02-23 16:37 \d tablename with psql over slow links... mallah@trade-india.com
2003-02-23 16:58 ` Re: \d tablename with psql over slow links... Tom Lane <tgl@sss.pgh.pa.us>
@ 2003-02-24 03:13 ` mallah@trade-india.com
0 siblings, 0 replies; 5+ messages in thread
From: mallah@trade-india.com @ 2003-02-24 03:13 UTC (permalink / raw)
To: tgl@sss.pgh.pa.us; +Cc: mallah@trade-india.com; pgsql-admin
here is output of
$ diff -c <original> <modified>
sorry i am not too familiar with diff.
> <mallah@trade-india.com> writes:
>> below is the diff for describe.c
>
> "diff -c" please. Without context a diff is essentially worthless, since your version of the
> input file is unlikely to match development sources.
>
> regards, tom lane
>
> ---------------------------(end of broadcast)--------------------------- TIP 6: Have you
> searched our list archives?
>
> http://archives.postgresql.org
-----------------------------------------
Get your free web based email at trade-india.com.
"India's Leading B2B eMarketplace.!"
http://www.trade-india.com/
Attachments:
describe.diff (application/octet-stream, 2.9K) download
*** describe.c 2003-02-23 13:11:17.000000000 +0530
--- ../psql/describe.c 2003-02-23 21:17:12.000000000 +0530
***************
*** 636,641 ****
--- 636,642 ----
char **ptr;
PQExpBufferData title;
unsigned int cols = 0;
+ unsigned int defaultcol = 5;
struct
{
bool hasindex;
***************
*** 702,710 ****
--- 703,721 ----
printfPQExpBuffer(&buf, "SELECT a.attname,");
appendPQExpBuffer(&buf, "\n pg_catalog.format_type(a.atttypid, a.atttypmod),\n"
" a.attnotnull, a.atthasdef, a.attnum");
+
if (verbose)
appendPQExpBuffer(&buf, ", pg_catalog.col_description(a.attrelid, a.attnum)");
+
+ /* my code additions 1 */
+ appendPQExpBuffer(&buf, ", (SELECT substring(adsrc for 128) FROM pg_catalog.pg_attrdef WHERE adrelid =%s AND adnum = a.attnum ) " , oid );
+ /* ends 1 */
+
+
appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_attribute a");
+
+
+
if (tableinfo.relkind == 'i')
appendPQExpBuffer(&buf, ", pg_catalog.pg_index i");
appendPQExpBuffer(&buf, "\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped", oid);
***************
*** 713,718 ****
--- 724,731 ----
appendPQExpBuffer(&buf, "\nORDER BY a.attnum");
res = PSQLexec(buf.data, false);
+
+
if (!res)
goto error_return;
***************
*** 740,745 ****
--- 753,759 ----
{
/* Name */
cells[i * cols + 0] = PQgetvalue(res, i, 0); /* don't free this
+
* afterwards */
/* Type */
cells[i * cols + 1] = PQgetvalue(res, i, 1); /* don't free this
***************
*** 751,777 ****
{
cells[i * cols + 2] = xmalloc(128 + 128);
cells[i * cols + 2][0] = '\0';
if (strcmp(PQgetvalue(res, i, 2), "t") == 0)
strcat(cells[i * cols + 2], "not null");
/* handle "default" here */
if (strcmp(PQgetvalue(res, i, 3), "t") == 0)
{
- PGresult *result;
-
- printfPQExpBuffer(&buf,
- "SELECT substring(d.adsrc for 128) FROM pg_catalog.pg_attrdef d\n"
- "WHERE d.adrelid = '%s' AND d.adnum = %s",
- oid, PQgetvalue(res, i, 4));
-
- result = PSQLexec(buf.data, false);
-
if (cells[i * cols + 2][0])
strcat(cells[i * cols + 2], " ");
strcat(cells[i * cols + 2], "default ");
- strcat(cells[i * cols + 2], result ? PQgetvalue(result, 0, 0) : "?");
! PQclear(result);
}
}
--- 765,787 ----
{
cells[i * cols + 2] = xmalloc(128 + 128);
cells[i * cols + 2][0] = '\0';
+
+
if (strcmp(PQgetvalue(res, i, 2), "t") == 0)
strcat(cells[i * cols + 2], "not null");
/* handle "default" here */
if (strcmp(PQgetvalue(res, i, 3), "t") == 0)
{
if (cells[i * cols + 2][0])
strcat(cells[i * cols + 2], " ");
+
strcat(cells[i * cols + 2], "default ");
! if (verbose)
! defaultcol = 6;
! strcat(cells[i * cols + 2], PQgetvalue(res, i, defaultcol ) );
!
}
}
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: \d tablename with psql over slow links...
2003-02-23 16:37 \d tablename with psql over slow links... mallah@trade-india.com
@ 2003-02-24 03:55 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-02-24 05:10 ` Re: \d tablename with psql over slow links... Rajesh Kumar Mallah <mallah@trade-india.com>
1 sibling, 1 reply; 5+ messages in thread
From: Tom Lane @ 2003-02-24 03:55 UTC (permalink / raw)
To: mallah@trade-india.com; +Cc: pgsql-admin
<mallah@trade-india.com> writes:
> I observed that a table which used to take 16 secs with \d was only taking
> 6 secs if the query for default attribute values are shifted to top level query in
> psql/describe.c ( function describeOneTableDetails ) .
I've applied this patch with some small improvements (to shortcircuit
the sub-SELECT for columns with no default).
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: \d tablename with psql over slow links...
2003-02-23 16:37 \d tablename with psql over slow links... mallah@trade-india.com
2003-02-24 03:55 ` Re: \d tablename with psql over slow links... Tom Lane <tgl@sss.pgh.pa.us>
@ 2003-02-24 05:10 ` Rajesh Kumar Mallah <mallah@trade-india.com>
0 siblings, 0 replies; 5+ messages in thread
From: Rajesh Kumar Mallah @ 2003-02-24 05:10 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-admin
thank you.
On Monday 24 February 2003 09:25 am, Tom Lane wrote:
> <mallah@trade-india.com> writes:
> > I observed that a table which used to take 16 secs with \d was only
> > taking 6 secs if the query for default attribute values are shifted to
> > top level query in psql/describe.c ( function describeOneTableDetails )
> > .
>
> I've applied this patch with some small improvements (to shortcircuit
> the sub-SELECT for columns with no default).
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
--
Regds
Mallah
----------------------------------------
Rajesh Kumar Mallah,
Project Manager (Development)
Infocom Network Limited, New Delhi
phone: +91(11)6152172 (221) (L) ,9811255597 (M)
Visit http://www.trade-india.com ,
India's Leading B2B eMarketplace.
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2003-02-24 05:10 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-02-23 16:37 \d tablename with psql over slow links... mallah@trade-india.com
2003-02-23 16:58 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-02-24 03:13 ` mallah@trade-india.com
2003-02-24 03:55 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-02-24 05:10 ` Rajesh Kumar Mallah <mallah@trade-india.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox