简体   繁体   English

我应该如何改善查询性能?

[英]How should I improve my query performance?

I have created a table with a couple of columns. 我创建了一个包含几列的表。

MyTable MyTable

  • Column1 -> RecordId (int) 列1-> RecordId(int)
  • Column2 -> Title (varchar) 列2->标题(varchar)
  • Column3 -> Shortname (varchar) 列3->简称(varchar)
  • Column4 -> (varchar) 列4->(varchar)
  • Column5 -> varchar 列5-> varchar

    ... ...

    ... ...

  • Column10 -> varchar 列10-> varchar

I am not joining this table with any other tables. 我没有将此表与其他任何表一起加入。 I have 4 rows of data in the table. 我表中有4行数据。

When I am querying for title, shortname for a particular RecordId, the query seems to be too slow. 当我查询特定RecordId的标题,简称时,查询似乎太慢了。 It nearly takes 7 seconds to load the page. 加载页面几乎需要7秒钟。

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. 我正在从我的jsp建立数据库连接,以便在列表框中显示查询结果。

My code looks something like this- conn= DataObjectConnectionPool.getInstance().getConnection(); 我的代码看起来像这样-conn = DataObjectConnectionPool.getInstance()。getConnection(); prepStmt = conn.prepStmt("select title,shortname from MyTable where RecordId=1"); prepStmt = conn.prepStmt(“从MyTable中选择标题,短名称,其中RecordId = 1”);

You should define a primary key on RecordId. 您应该在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. 如果您的页面在7秒内加载,并且表中只有4行数据,那么问题几乎可以肯定是在DBMS中。

There is absolutely no point to creating indexes on a table with 4 rows. 在具有4行的表上创建索引绝对没有意义。 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. 如果要在dbms中查看执行查询的时间,请在运行查询后从程序包缓存中获取一些数据。

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. 该表函数中还有100个其他列,涉及不同类型的等待等。

Basically you are using this sql query in your code: 基本上,您在代码中使用以下sql查询:

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 ==> 从数据库端,您可以通过在RecordID列上创建索引然后执行runstats ==>来加快查询速度。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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