简体   繁体   中英

How should I improve my query performance?

I have created a table with a couple of columns.

MyTable

  • Column1 -> RecordId (int)
  • Column2 -> Title (varchar)
  • Column3 -> Shortname (varchar)
  • Column4 -> (varchar)
  • Column5 -> varchar

    ...

    ...

  • Column10 -> varchar

I am not joining this table with any other tables. I have 4 rows of data in the table.

When I am querying for title, shortname for a particular RecordId, the query seems to be too slow. It nearly takes 7 seconds to load the page.

I haven't used any indexing on my tables. Can you please suggest how do I improve my table/query performance?

I am making db connection from my jsp in order to display the query results in the listbox.

My code looks something like this- conn= DataObjectConnectionPool.getInstance().getConnection(); prepStmt = conn.prepStmt("select title,shortname from MyTable where RecordId=1");

You should define a primary key on RecordId.

This will have the side-effect of creating an index on that column.

BUT

If your page is loading in 7 seconds, and you only have 4 rows of data in the table, then the problem is almost certainly not in the DBMS.

There is absolutely no point to creating indexes on a table with 4 rows. If you would like to see the time in the dbms for the execution of your query, grab some data from the package cache after you run the query.

select num_exec_with_metrics, total_act_time,  pool_read_time
  from table(mon_get_pkg_cache_stmt(null,null,null,null))

There are 100 other columns in that table function involving different types of waits, etc.

Basically you are using this sql query in your code:

select title,shortname from MyTable where RecordId=1

From the database end you can speed up the query by creating index on the RecordID column and then doing runstats ==>

create index MyIndex on MyTable (RecordID) Compress yes Allow reverse scans;
runstats on table Mytable and indexes all shrlevel change;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM