[英]using multicolumn index in Jackcess to match on first column
我使用Jackcess 2.1.5從具有colA和colB上多列索引的Access 2003表中讀取數據。 給定colA 和 colB的值,這可以正常工作。
現在從理論上講,這樣的索引可用於獲取僅與colA值匹配的所有行。 但是,如何與Jackcess一起執行此操作? 我無法通過使用newEntryIterable
或EntryIterableBuilder
使其工作
Table table = access.getTable("tbl");
Index index = table.getIndex("index"); //index spanning two columns
IndexCursor cursor = CursorBuilder.createCursor(index);
for (Row row : cursor.newEntryIterable(val)) { //error: missing argument
for (Row row : cursor.newEntryIterable(val, null)) { //returns rows where colB == null
//some code
}
目前,我還有另一個僅涵蓋colA的索引。 這是唯一的解決方案嗎?
我只是嘗試了以下方法,它為我工作。 對於名為“人”的表
ID FirstName LastName
-- --------- --------
1 Gord Thompson
2 Jimmy Hoffa
3 Jimmy Buffett
4 Bob Loblaw
在(FirstName, LastName)
上使用名為“ FirstLast”的索引的代碼
Table tbl = db.getTable("People");
IndexCursor cur = CursorBuilder.createCursor(tbl.getIndex("FirstLast"));
Map<String, String> criteria = Collections.singletonMap("FirstName", "Jimmy");
boolean found = cur.findFirstRow(criteria);
if (found) {
boolean nextRowExists = true;
do {
Row r = cur.getCurrentRow();
System.out.println(r.getString("LastName"));
nextRowExists = cur.moveToNextRow();
} while (nextRowExists && cur.currentRowMatches(criteria));
} else {
System.out.println("(No matches found.)");
}
印制
Buffett
Hoffa
但是,隨后對網絡共享上的大文件進行的測試表明,與使用.newEntryIterable
和僅對FirstName
單獨使用索引相比,上述方法的效率要低得多。 如果性能很重要,那么您應該只為colA
保留該額外索引。
我知道這有點晚了,但是我想添加一個更新。 從2.1.7版本開始,Jackcess現在支持部分索引查找。 因此,從原始問題開始,此行現在將用於查找與雙列索引的第一列匹配的所有條目:
for (Row row : cursor.newEntryIterable(val)) {
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.