473,799 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ 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 2026
Ken Guest <kg****@stockby te.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 YourEmailAddres sHere" to ma*******@postg resql.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*******@postg resql.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*******@postg resql.org

Nov 12 '05 #6

"scott.marl owe" <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
4209
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 machine I get a message that the remote machine IP address is not specified in pg_hba.conf, that there is no record of that machine there. ph_hba.conf is set up correctly, because when I run the following: postmaster -i -D /var/lib/pgsql/data...
7
6668
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 the whole db changed over in 1 hour. Since the upgrade I have been getting the following error message sporadically.
18
2029
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 backend or have a separate "proxy" which handles the replication. The main problem with incorporating the system into the backend process is that it limits the development to the 10-month timeframe between releases. The main advantage is that...
4
5165
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 cannot find any clues on what to do... Apparently money cannot be cast to anything. I don't think it will be hard to write a custom tcl/perl script that takes a "copy checks to...." command to do the task
8
2031
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 is: Student (name Varchar, age integer);
18
5155
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 observations I've recently made. The core of the problem is that Postgres is filling up my hard drive with swap files at the rate of around 3 to 7 GB per week (that's Gigabytes not Megabytes) . At this rate it takes roughly two months to fill up my 40...
2
1132
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, the text of the email that will be sent to their friend is presented on screen. If they like it, they press send, and an email is sent to their friend. The main body of the email is in a variable, which contains paragraph formatting etc. The...
1
3869
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 find libpq-fe.h. Please specify correct PostgreSQL installation path I tried downloading Postgres source and modifying PHPs configure to point to it, and that worked. But then compilation failed, e.g.
0
2707
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 works for files larger than 8000 Bytes. If a file is less than 1000 Bytes I get the following message: Error message: --invalid input syntax for type oid: "\074\077......";
0
9689
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9550
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10269
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9085
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7573
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5597
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4148
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.