arsenal
arsenal

Reputation: 24144

Index working in 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);

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%';

Upvotes: 0

Views: 818

Answers (1)

Raihan
Raihan

Reputation: 10395

A leading wildcard with the like operator will make oracle to ignore the index on urlHash.

You can do either of the follwing for better performance:

  1. use index hints with select

    select /*+index(tableName,hash_date_idx)*/ * from tabelName ...
    
  2. use full text indexing CONTEXT on urlHash column.

Upvotes: 2

Related Questions