3

I have a existing query in the system which is a simple select query as follows:

SELECT <COLUMN_X>, <COLUMN_Y>, <COLUMN_Z> FROM TABLE <WHATEVER>

Over time, <WHATEVER> is growing in terms of records. Is there any way possible to improve the performance here? The developer is using Statement interface. I believe PreparedStatement won't help here since the query is executed only once.

Is there any thing else that can be done? One of the columns is a primary key and others are VARCHAR (if the information helps)

7
  • You need three columns from all rows in the table? Commented Nov 3, 2011 at 0:26
  • 1
    which part is slow? the query or the java code? did you try it in sqlplus or toad?
    – soulcheck
    Commented Nov 3, 2011 at 0:39
  • How much data is there? Are you sending it over a network?
    – Jon Heller
    Commented Nov 3, 2011 at 4:48
  • @jonearles: Currently, there are close to 5K records (increased from previous 3.5K) and no I am not sending it over a network. Commented Nov 3, 2011 at 4:57
  • 1
    Have you measured exactly where it is "too slow"? Getting a lot of data will take a lot of time. Commented Nov 3, 2011 at 9:19

2 Answers 2

2

Does you query have any predicates? Or are you always returning all of the rows from the table?

If you are always returning all the rows, a covering index on column_x, column_y, column_z would allow Oracle to merely scan the index rather than doing a table scan. The query will still slow down over time but the index should grow more slowly than the table.

If you are returning a subset of rows, there are potentially other indexes that would be more advantageous from a performance perspective.

1
  • No, the query does not have any predicates. And yes, I have to return all the rows from the table all the time. Thank you for your feedback, I will implement your suggestions and get back to you with the results. Commented Nov 4, 2011 at 14:49
2

Are there any optimization you can do outside of the SQL query tunning? If yes here are some suggestion:

  • Try putting the table in memory (like the MEMORY storage engine in MySQL) or any other optimization in the DB
  • Cache the ResultSet in java. query again only when the table content changes. If the table only has inserts and no updates or delete (wishful thinking), then you can use SELECT COUNT(*) FROM table. If the rows returned are different than the previous time then fire your original query and update cache only if needed.

Not the answer you're looking for? Browse other questions tagged or ask your own question.