public abstract class ArticleDetail extends ArticleList
implements Editable, Deletable {
/**
 * @subject PostgreSQL Tuning: BIGINT
 * @topics Java Blog Code
 * @permalink PostgreSQL_Tuning_BIGINT
 * @trackback http://www.hjsoft.com/blog/trackback/PostgreSQL_Tuning_BIGINT
 * @author john
 * @created 6/17/04 10:30:24 AM
 * @modified 7/6/04 1:04:26 PM
 */

I luckily stumbled upon this blog about PostgreSQL indexing. I never really considered that it would be my database holding me back much, but it seems I should really analyze the queries my app server is creating.

Basically, searching against BIGINT keys doesn't take advantage of the index, since it has to cast internally from INT4 (integer) in the query to an INT8 (bigint). I'm using java.lang.Long in my Java code for my keys, so I wouldn't want to just drop back to integer in the database -- I could get away with it for now, but it's not very future-proof.

In spite of NUMERIC(18,0) index scans being slower than BIGINT index scans, they'll beat out sequential scans of BIGINT, which is what my blog is doing now. I'm testing it out in my development copy, but I'll probably have to test it in the production version of my blog to get a real feel for it.

At this point, I must settle for NUMERIC(18,0) instead of casting my input parameters to bigint, since I know of no way to tune my queries created by JBoss' CMP implementation.

Update (6 July 2004): I haven't done any real benchmarks, but I really must wonder how to really test the plan for prepared statements in Postgres' JDBC driver. Many of the links I had read referred to Postgres 7.3, but I'm running 7.4 these days. Using Numeric also didn't feel much faster, so I'm trying Integer now, but I may revert back to Bigint down the road, since I really am using Long in my java code.

public Comments displayComments() {
/*
 * John M Flinchbaugh
 * http://www.hjsoft.com/blog/link/test_trackback_post
 * 7/3/04 1:59:55 AM
 * test trackback post
 */

testing

/*
 * swr
 * 7/6/04 4:39:18 PM
 * cast to int8
 */
You have to cast the argument in the SQL to int8. Then postgresql will know to use the int8 index.

Something like this:

select * from foo where bar = ?

where bar is a bigint (int8) column, won't use the index if the bound argument can fit in an int4. But if you do this instead:

select * from foo where bar = (int8)?

it will use the index.
/*
 * swr
 * 7/6/04 4:47:38 PM
 *
 */
Oops sorry, it's int8(?) not (int8)?. It's a function.
}
public Comment postNewComment() {
Name:
Email (hidden):
URL:
Subject:
Body:
 
 
}
}
 
Robots, look here.