Oracle 中的索引工作
String s1 = "create table " +tableName+
"(id number NOT NULL PRIMARY KEY, " +
"url varchar(1000) NOT NULL, " +
"urlHash varchar(255) NOT NULL, " +
"contentHash varchar(255), " +
"modDate varchar(30), " +
"contentLocation varchar(100), " +
"status integer, " +
"lastCrawlDate varchar(30)) ";
String s3 = "create sequence " +sequenceName+ " start with 1 increment by 1 nomaxvalue";
stmt=conn.createStatement();
stmt.executeUpdate(s1);
stmt.executeUpdate(s3);
ps = conn.prepareStatement (
"INSERT INTO testing (id, url, urlHash, contentHash, modDate, contentLocation, status, lastCrawlDate) VALUES(test_seq.nextval,?,?,?,?,?,?,?)");
ps.setString (1, url);
ps.setString (2, urlHash);
ps.setString (3, contentHash);
ps.setString (4, modDate);
ps.setString (5, contentLocation);
ps.setLong (6, status);
ps.setString (7, lastCrawlDate);
我的选择查询将围绕 urlHash 和 modDate 展开。因此,如果我在这些列上创建索引。
CREATE INDEX hash_date_idx ON tableName (urlHash asc, modDate asc);
然后,如果我基于这两列或单列触发选择查询,那么后台会发生什么。谁能解释一下,因为我是 Oracle 数据库世界的新手。而在这种情况下一般什么样的索引是最好的。我们应该在什么基础上使用它。
Select * from tabelName where urlHash like '%asdreefjhsawofjkwjfkwqdskdjksdwq%';
String s1 = "create table " +tableName+
"(id number NOT NULL PRIMARY KEY, " +
"url varchar(1000) NOT NULL, " +
"urlHash varchar(255) NOT NULL, " +
"contentHash varchar(255), " +
"modDate varchar(30), " +
"contentLocation varchar(100), " +
"status integer, " +
"lastCrawlDate varchar(30)) ";
String s3 = "create sequence " +sequenceName+ " start with 1 increment by 1 nomaxvalue";
stmt=conn.createStatement();
stmt.executeUpdate(s1);
stmt.executeUpdate(s3);
ps = conn.prepareStatement (
"INSERT INTO testing (id, url, urlHash, contentHash, modDate, contentLocation, status, lastCrawlDate) VALUES(test_seq.nextval,?,?,?,?,?,?,?)");
ps.setString (1, url);
ps.setString (2, urlHash);
ps.setString (3, contentHash);
ps.setString (4, modDate);
ps.setString (5, contentLocation);
ps.setLong (6, status);
ps.setString (7, lastCrawlDate);
And my select query will revolve around urlHash and modDate. So if I create an index on these columns.
CREATE INDEX hash_date_idx ON tableName (urlHash asc, modDate asc);
And then if I fire select query based on these two columns or single column then what will happen in background. Can anyone explain that as I am new to oracle database world. And what kind of index is generally the best in this case. And on what basis we should use one.
Select * from tabelName where urlHash like '%asdreefjhsawofjkwjfkwqdskdjksdwq%';
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
带有
like
运算符的前导通配符将使 oracle 忽略urlHash
上的索引。您可以执行以下任一操作以获得更好的性能:
使用带有 select 的索引提示
在
urlHash
列上使用全文索引 CONTEXT。A leading wildcard with the
like
operator will make oracle to ignore the index onurlHash
.You can do either of the follwing for better performance:
use index hints with select
use full text indexing CONTEXT on
urlHash
column.