簡體   English   中英

在Oracle 12c中查詢和排序大表

[英]Querying and sorting a big table in Oracle 12c

假設我有一個個人數據表Table1first_namelast_namedate_of_birthaddress 數百萬行。 我應該創建什么索引才能在以下查詢中快速運行:

select * from Table1 where date_of_birth > some_date and contains(address,'some street') > 0 order by first_name offset 100 rows fetch next 5 rows only;

select * from Table1 where date_of_birth > some_date and contains(address,'some street') > 0 order by last_name offset 100 rows fetch next 5 rows;

這是一個簡化的案例,但是我想弄清楚的是如何為類似於ebay的網站構建數據庫結構,即幾個排序順序,幾個數字參數和文本描述。 我已經在address上有文本索引

索引是否有用取決於各種條件。

  • 數據的分布(例如表中date_of_birth范圍)
  • 選擇參數(例如, date_of_birth > 1900-01-01選擇)
  • 您選擇的預期結果集(排序依據)
  • 桌子尺寸
  • 您的數據庫環境
  • ...

在某些情況下,全表掃描是更好的選擇。

要決定這一點,您必須研究表的數據,檢查業務案例,調查執行計划

在某些情況下,您可以改善選擇語句。

例如

使用上限限制date_of_birth的范圍。

where date_of_birth between some_date and some_date +7

這與您的select語句不同(僅在此范圍內按名稱排序),但可能足夠好,可以顯着提高性能

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM