473,491 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

formatting of SQL sent by PHP to postgres

Folks,
I have a question or two regarding PHP and Postgres on the issue of
speed:
1. Is the semicolon at the end of SQL superflous when sent to Postgres?
Should it make much of a difference if I removed it?

2. A lot of SQL issued have white space characters (newlines, tabs and
spaces) present - does this have any [major] impact on how quick
postgres gets to execute the SQL and return results?

k.
--
Ken Guest
Senior Developer
Stockbyte Royalty Free Photos
http://www.stockbyte.com

__________________________________________________ ______________________
This email has been scanned for all viruses by the MessageLabs Email
Security System. For more information on a proactive email security
service working around the clock, around the globe, visit
http://www.messagelabs.com
__________________________________________________ ______________________

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 12 '05 #1
7 2005
Ken Guest <kg****@stockbyte.com> writes:
1. Is the semicolon at the end of SQL superflous when sent to Postgres?
Should it make much of a difference if I removed it?
Yes; no.
2. A lot of SQL issued have white space characters (newlines, tabs and
spaces) present - does this have any [major] impact on how quick
postgres gets to execute the SQL and return results?


No. I doubt you could measure the impact at all ... unless you are
talking many kilobytes of whitespace, in which case the data
transmission overhead might be noticeable.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 12 '05 #2
On Thu, 30 Oct 2003, Ken Guest wrote:
Folks,
I have a question or two regarding PHP and Postgres on the issue of
speed:
1. Is the semicolon at the end of SQL superflous when sent to Postgres?
Should it make much of a difference if I removed it?
Yes, you can get rid of it. No, it won't make any real difference.
2. A lot of SQL issued have white space characters (newlines, tabs and
spaces) present - does this have any [major] impact on how quick
postgres gets to execute the SQL and return results?


Other than the very tiny increase in time needed to send the extra blank
spaces across the wire, no, it won't have any real effect on the
performance of the database.

It's far more likely that optimizing your SQL queries will yield the
greatest increase in performance. Things like replacing "select max(id)
from table" with "select id from table order by id desc limit 1" etc...
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #3

On Thu, 30 Oct 2003, Scott Marlowe wrote:
"It's far more likely that optimizing your SQL queries will yield the
greatest increase in performance. Things like replacing "select max(id)
from table" with "select id from table order by id desc limit 1" etc..."

When I first read this I was surprised that this kind of change could even
make
a difference. I tested it and it makes a lot of difference.

Ex.
On a table with 21,000 records I ran 2 queries. One using "Max(Num)" and one
using the "order by num desc limit 1". The "Max(Num)" query took 51 msec and
the other took 0.09 msec. I tried the same thing on SQL Server and the 2
queries run in exactly the same amount of time. Why does it make so much of
a
difference in PostgreSQL? I did notice in the query plan, the second query
was
able to use the index on the Num field - this may be the speed difference..

I'm running pgsql v7.3.2 on redhat 9.

Also, are there any other "tricks" for optimizing this way? I have a vb app
I'm porting to PostgreSQL from SQL Server and it seems a lot of the queries,
etc take a lot longer... I'm starting to think it may be ODBC or something
slowing me up but that I can ask about on the other mailing list...
David Green
Sage Automation, Inc.
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 12 '05 #4
On Thu, 30 Oct 2003, David Green wrote:

On Thu, 30 Oct 2003, Scott Marlowe wrote:
"It's far more likely that optimizing your SQL queries will yield the
greatest increase in performance. Things like replacing "select max(id)
from table" with "select id from table order by id desc limit 1" etc..."

When I first read this I was surprised that this kind of change could even
make
a difference. I tested it and it makes a lot of difference.


Postgresql's MVCC design makes it hard to use indexes for aggregate
functions. So, if you use something like max(id), postgresql literally
has to seq scan the table to find the max(id). MVCC allows postgresql to
handle massive parallel load. It causes some minor performance issues
like that that are hard to code around cleanly.
Also, are there any other "tricks" for optimizing this way? I have a vb app
I'm porting to PostgreSQL from SQL Server and it seems a lot of the queries,
etc take a lot longer... I'm starting to think it may be ODBC or something
slowing me up but that I can ask about on the other mailing list...


Sure, make sure your ODBC connector is set up to use cursors, so it
doesn't have to wait for the whole dataset to return before becoming
responsive.

Avoid lots of updates, i.e. don't issue a "update table set field=1" with
no where clause all the time.

Install the autovacuum daemon

Read the performance hints in both the performance tuning section of the
docs, and on varlena:

http://www.varlena.com/varlena/Gener...bits/perf.html

And browse the performance mailing list, lots of good stuff in there.
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 12 '05 #5
On Thu, 2003-10-30 at 15:57, scott.marlowe wrote:
On Thu, 30 Oct 2003, David Green wrote:

On Thu, 30 Oct 2003, Scott Marlowe wrote:
"It's far more likely that optimizing your SQL queries will yield the
greatest increase in performance. Things like replacing "select max(id)
from table" with "select id from table order by id desc limit 1" etc..."

When I first read this I was surprised that this kind of change could even
make
a difference. I tested it and it makes a lot of difference.


Postgresql's MVCC design makes it hard to use indexes for aggregate
functions. So, if you use something like max(id), postgresql literally
has to seq scan the table to find the max(id). MVCC allows postgresql to
handle massive parallel load. It causes some minor performance issues
like that that are hard to code around cleanly.
Also, are there any other "tricks" for optimizing this way? I have a vb app
I'm porting to PostgreSQL from SQL Server and it seems a lot of the queries,
etc take a lot longer... I'm starting to think it may be ODBC or something
slowing me up but that I can ask about on the other mailing list...


Sure, make sure your ODBC connector is set up to use cursors, so it
doesn't have to wait for the whole dataset to return before becoming
responsive.

Avoid lots of updates, i.e. don't issue a "update table set field=1" with
no where clause all the time.

Install the autovacuum daemon

Read the performance hints in both the performance tuning section of the
docs, and on varlena:

http://www.varlena.com/varlena/Gener...bits/perf.html

And browse the performance mailing list, lots of good stuff in there.


Isn't sql server one of the databases that does rewriteing of (what we
consider) explicit join plans? If so your "style" of sql queries may be
slower in postgresql, but theres a fix for this in postgresql 7.4 (which
should be released soon, so probably worth testing on)

Robert Treat
--
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 12 '05 #6

"scott.marlowe" <sc***********@ihs.com> writes:
Postgresql's MVCC design makes it hard to use indexes for aggregate
functions. So, if you use something like max(id), postgresql literally
has to seq scan the table to find the max(id). MVCC allows postgresql to
handle massive parallel load. It causes some minor performance issues
like that that are hard to code around cleanly.


That postgres doesn't use indexes for max/min is really not related to MVCC.
It would be a lot of work to do so and involve changes to lots of places and
it just hasn't been done yet. But it can be done and would be just as hard
without MVCC.

You're thinking of caching aggregate results for things like count(). That's
where supporting transactions makes it hard. But that's really unrelated to
min/max and indexes.

--
greg
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #7
Le Jeudi 30 Octobre 2003 21:19, David Green a écrit :
On Thu, 30 Oct 2003, Scott Marlowe wrote:
"It's far more likely that optimizing your SQL queries will yield the
greatest increase in performance. Things like replacing "select max(id)
from table" with "select id from table order by id desc limit 1" etc..."


When I first read this I was surprised that this kind of change could even
make
a difference. I tested it and it makes a lot of difference.

Ex.
On a table with 21,000 records I ran 2 queries. One using "Max(Num)" and
one using the "order by num desc limit 1". The "Max(Num)" query took 51
msec and the other took 0.09 msec. I tried the same thing on SQL Server and
the 2 queries run in exactly the same amount of time. Why does it make so
much of a difference in PostgreSQL? I did notice in the query plan, the
second query was able to use the index on the Num field - this may be the
speed difference..


This is a good thing but remember that will run only if you have an index on
the "Num" Column ... and if you have not null value in the field !
Otherwise you will get a better result with MAX function.

regards,
--
Hervé Piedvache

Elma Ingénierie Informatique
6 rue du Faubourg Saint-Honoré
F-75008 - Paris - France
Pho. 33-144949901
Fax. 33-144949902
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4162
by: N.K. | last post by:
Hi, I've just installed postgres on the Linux server. It is supposed to start automatically which I think it does since I can run an sql stmt right away. When I'm trying to connect from a remote...
7
6634
by: Abdul-Wahid Paterson | last post by:
Hi, I have had a site working for the last 2 years and have had no problems until at the weekend I replace my database server with a newer one. The database migration went like a dream and I had...
18
1996
by: Chris Travers | last post by:
Hi all; I have been looking into how to ensure that synchronous replication, etc. could best be implimented. To date, I see only two options: incorporate the replication code into the database...
4
5125
by: Jerry | last post by:
Is it possible to turn off the "$" and "," that appear in "money" formatted columns so I can dump the table in a numeric format? The man page hints that lc_monetary controls the formatting but I...
8
2008
by: Vinay Jain | last post by:
Hi.. I am newbe in postgresql so please help me though the question may be very easy to answer.. Is there any formatting function to get output with fix lengths..for example my query is.. schema...
18
5087
by: Joe Lester | last post by:
This thread was renamed. It used to be: "shared_buffers Question". The old thread kind of died out. I'm hoping to get some more direction by rephrasing the problem, along with some extra...
2
1119
by: Jim | last post by:
Hi All, I would appreciate a pointer on this problem, if you please. I am writing a 'tell a friend' page for my www site. Essentially, the user opens the page, fills out a form, click submit,...
1
3852
by: Jack Orenstein | last post by:
I'm trying to configure PHP 5.2.0 with support for Postgres 8.1.3. Postgres was installed with FC5 without source. PHP's configure needs source. When I run configure: configure: error: Cannot...
0
2683
by: NM | last post by:
Hello, I've got a problem inserting binary objects into the postgres database. I have binary objects (e.g. images or smth else) of any size which I want to insert into the database. Funny is it...
0
7115
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7154
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7190
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6858
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5451
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4578
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3086
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
280
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.