If you're going to use a boolean condition in your where clause, you're going to want to make sure you use an operator so that the index is used (if present).
For example, this will not use the index:
db=> SELECT id FROM users WHERE active;
This will use the index:
db=> SELECT id FROM users WHERE active = true;
expressionsgotchaindexperformancepostgresqlsql
Use the form ::type to ensure that a value is cast to the proper type:
SELECT * FROM table WHERE column = 5::bigint;
In this case, column is indexed and is a bigint. The index will not be used if the query planner doesn't encounter a value of the index type. Note: this only applies in PostgreSQL 7.x.
gotchaindexperformancepostgresqlsqlsyntaxtypes
If you have a query like this:
SELECT max(some_column) FROM mytable WHERE ...;
and you want to eliminate the sequence scan that kills the query's performance, an alternative is:
SELECT some_column FROM mytable WHERE ... ORDER BY some_column DESC LIMIT 1;
MIN and MAX aggregates can be eliminated this way.
aggregatesmaxminperformancepostgresqlqueriesscansql
Open about:config in a new tab and make the following changes:
network.http.pipelining -> True network.http.pipelining.maxrequests -> 10
Anywhere on the screen, right-click and add a new integer:
nglayout.initialpaint.delay -> 0
If you're using a proxy, also change the proxy versions:
network.http.pipelining.proxy.pipelining -> True
WARNING: Be conservative when setting your pipelining settings. To the untrained eye this feature looks like a DOS attempt on the server side and might get you blocked.
browserconfigurationfirefoxgotchanetworkperformance
Use explain:
EXPLAIN SELECT * FROM some_table WHERE condition;
analysisexplainperformancepostgresqlsql
If you want to see how long a query is taking to run, you can either run explain analyze or enable timing for the client by typing \timing.
analysisconfigurationdebuggingdurationoutputperformancepostgresqlpsqlruntimesqltiming