【问题标题】:Column is not indexed even though it is. PreparedStatement inside列没有被索引,即使它是。 PreparedStatement里面
【发布时间】:2011-11-11 14:46:06
【问题描述】:

我真的在为一个没有出现在我的开发环境中的错误而苦苦挣扎,只有在测试中部署过一次。

我正在使用准备好的语句连续运行大约 30 000 个查询。查询使用 oracle 模糊方法检查字符串与我们数据库中的内容的相似性。

检查的列被索引了,但是,不知道为什么,经过一些迭代后随机失败,说索引不存在。

我不明白发生了什么,因为索引确实存在。我的方法从不重建或删除索引,因此没有理由出现此错误...

public List<EntryToCheck> checkEntriesOnSuspiciousElement(List<EntryToCheck> entries, int type,int score, int numresults, int percentage) throws Exception {
    Connection connection = null;
    PreparedStatement statementFirstName = null;
    PreparedStatement statementLastname = null;

    int finalScore = checkScore(score);
    int finalNumResults = checkNumResults(numresults);
    int finalPercentage = checkPercentage(percentage);
    try {
    connection = dataSource.getConnection();

    StringBuilder requestLastNameOnly = new StringBuilder("SELECT SE.ELEMENT_ID, SE.LASTNAME||' '||SE.FIRSTNAME AS ELEMENT, SCORE(1) AS SCORE ");
    requestLastNameOnly.append("FROM BL_SUSPICIOUS_ELEMENT SE ");
    requestLastNameOnly.append("WHERE CONTAINS(SE.LASTNAME, 'fuzzy({' || ? || '},' || ? || ',' || ? || ', weight)', 1)>? ");
    requestLastNameOnly.append((type > 0 ? "AND SE.ELEMENT_TYPE_ID = ? " : " "));
    requestLastNameOnly.append("ORDER BY SCORE DESC");

    statementLastname = connection.prepareStatement(requestLastNameOnly.toString());
    for (EntryToCheck entryToCheck : entries) {
            ResultSet rs;
            boolean withFirstName = (entryToCheck.getEntryFirstname() != null && !entryToCheck.getEntryFirstname().equals("")); 
                statementLastname.setString(1, entryToCheck.getEntryLastname().replaceAll("'","''"));
                statementLastname.setInt(2, finalScore);
                statementLastname.setInt(3, finalNumResults);
                statementLastname.setInt(4, finalPercentage);

                if(type > 0){
                    statementLastname.setInt(5, type);
                }
                System.out.println("Query LastName : " +  entryToCheck.getEntryLastname().replaceAll("'","''") );
                rs = statementLastname.executeQuery();

            while (rs.next()) {

                Alert alert = new Alert();
                alert.setEntryToCheck(entryToCheck);
                alert.setAlertStatus(new AlertStatus(new Integer(AlertStatusId.NEW)));
                alert.setAlertDate(new Date());
                alert.setBlSuspiciousElement(new BlSuspiciousElement(new Integer(rs.getInt("ELEMENT_ID"))));
                alert.setMatching(rs.getString("ELEMENT") + " (" + rs.getInt("SCORE") + "%)");
                entryToCheck.addAlert(alert);
                }

        }
    }
        catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        finally {
            DAOUtils.closeConnection(connection, statementLastname);
        }

        return entries;
}

真的不知道看什么了……

谢谢!

F

【问题讨论】:

    标签: sql oracle indexing prepared-statement


    【解决方案1】:

    我从未使用过 Oracle 文本表,但我的建议是: 确保没有其他人同时在表上执行 DDL 语句。 另外,请确保您拥有的索引是上下文索引。

    【讨论】:

      【解决方案2】:

      为要应用搜索的列创建索引

      .......................................

      创建索引 "MTU219"."SEARCHFILTER" ON "BL_SUSPICIOUS_ELEMENT" ("LASTNAME") INDEXTYPE 是 "CTXSYS"."CONTEXT" PARAMETERS ('storage CTXSYS.ST_MTED_NORMAL SYNC(ON COMMIT)');

      .......................

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-02-01
        相关资源
        最近更新 更多