提交 05e0e57e authored 作者: Thomas Mueller's avatar Thomas Mueller

Fulltext search: Data is no longer deleted and re-inserted if the indexed columns didn't change.

上级 be8a9a43
...@@ -675,6 +675,16 @@ public class FullText { ...@@ -675,6 +675,16 @@ public class FullText {
} }
} }
static boolean hasChanged(Object[] oldRow, Object[] newRow, int[] indexColumns) {
for (int c : indexColumns) {
Object o = oldRow[c], n = newRow[c];
if (!o.equals(n)) {
return true;
}
}
return false;
}
/** /**
* Trigger updates the index when a inserting, updating, or deleting a row. * Trigger updates the index when a inserting, updating, or deleting a row.
*/ */
...@@ -777,9 +787,18 @@ public class FullText { ...@@ -777,9 +787,18 @@ public class FullText {
public void fire(Connection conn, Object[] oldRow, Object[] newRow) public void fire(Connection conn, Object[] oldRow, Object[] newRow)
throws SQLException { throws SQLException {
if (oldRow != null) { if (oldRow != null) {
delete(setting, oldRow); if (newRow != null) {
} // update
if (newRow != null) { if (hasChanged(oldRow, newRow, index.indexColumns)) {
delete(setting, oldRow);
insert(setting, newRow);
}
} else {
// delete
delete(setting, oldRow);
}
} else if (newRow != null) {
// insert
insert(setting, newRow); insert(setting, newRow);
} }
} }
......
...@@ -467,9 +467,18 @@ public class FullTextLucene extends FullText { ...@@ -467,9 +467,18 @@ public class FullTextLucene extends FullText {
public void fire(Connection conn, Object[] oldRow, Object[] newRow) public void fire(Connection conn, Object[] oldRow, Object[] newRow)
throws SQLException { throws SQLException {
if (oldRow != null) { if (oldRow != null) {
delete(oldRow); if (newRow != null) {
} // update
if (newRow != null) { if (hasChanged(oldRow, newRow, indexColumns)) {
delete(oldRow);
insert(newRow);
}
} else {
// delete
delete(oldRow);
}
} else if (newRow != null) {
// insert
insert(newRow); insert(newRow);
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论