提交 b731e1ed authored 作者: Thomas Mueller's avatar Thomas Mueller

Small performance optimization

上级 07ad5271
...@@ -58,6 +58,7 @@ public abstract class Prepared { ...@@ -58,6 +58,7 @@ public abstract class Prepared {
private Command command; private Command command;
private int objectId; private int objectId;
private int currentRowNumber; private int currentRowNumber;
private int rowScanCount;
/** /**
* Create a new object. * Create a new object.
...@@ -343,7 +344,10 @@ public abstract class Prepared { ...@@ -343,7 +344,10 @@ public abstract class Prepared {
* *
* @param rowNumber the row number * @param rowNumber the row number
*/ */
protected void setCurrentRowNumber(int rowNumber) { protected void setCurrentRowNumber(int rowNumber) throws SQLException {
if ((rowScanCount++ & 127) == 0) {
checkCanceled();
}
this.currentRowNumber = rowNumber; this.currentRowNumber = rowNumber;
} }
......
...@@ -53,7 +53,6 @@ public class Delete extends Prepared { ...@@ -53,7 +53,6 @@ public class Delete extends Prepared {
try { try {
setCurrentRowNumber(0); setCurrentRowNumber(0);
while (tableFilter.next()) { while (tableFilter.next()) {
checkCanceled();
setCurrentRowNumber(rows.size() + 1); setCurrentRowNumber(rows.size() + 1);
if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) { if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) {
Row row = tableFilter.get(); Row row = tableFilter.get();
...@@ -63,8 +62,11 @@ public class Delete extends Prepared { ...@@ -63,8 +62,11 @@ public class Delete extends Prepared {
rows.add(row); rows.add(row);
} }
} }
int rowScanCount = 0;
for (rows.reset(); rows.hasNext();) { for (rows.reset(); rows.hasNext();) {
checkCanceled(); if ((rowScanCount++ & 127) == 0) {
checkCanceled();
}
Row row = rows.next(); Row row = rows.next();
table.removeRow(session, row); table.removeRow(session, row);
session.log(table, UndoLogRecord.DELETE, row); session.log(table, UndoLogRecord.DELETE, row);
......
...@@ -93,7 +93,6 @@ public class Insert extends Prepared { ...@@ -93,7 +93,6 @@ public class Insert extends Prepared {
} }
} }
} }
checkCanceled();
table.fireBefore(session); table.fireBefore(session);
table.validateConvertUpdateSequence(session, newRow); table.validateConvertUpdateSequence(session, newRow);
table.fireBeforeRow(session, null, newRow); table.fireBeforeRow(session, null, newRow);
...@@ -110,7 +109,6 @@ public class Insert extends Prepared { ...@@ -110,7 +109,6 @@ public class Insert extends Prepared {
table.fireBefore(session); table.fireBefore(session);
table.lock(session, true, false); table.lock(session, true, false);
while (rows.next()) { while (rows.next()) {
checkCanceled();
count++; count++;
Value[] r = rows.currentRow(); Value[] r = rows.currentRow();
Row newRow = table.getTemplateRow(); Row newRow = table.getTemplateRow();
......
...@@ -132,7 +132,6 @@ public class Merge extends Prepared { ...@@ -132,7 +132,6 @@ public class Merge extends Prepared {
table.fireBefore(session); table.fireBefore(session);
table.lock(session, true, false); table.lock(session, true, false);
while (rows.next()) { while (rows.next()) {
checkCanceled();
count++; count++;
Value[] r = rows.currentRow(); Value[] r = rows.currentRow();
Row newRow = table.getTemplateRow(); Row newRow = table.getTemplateRow();
......
...@@ -155,7 +155,6 @@ public class Select extends Query { ...@@ -155,7 +155,6 @@ public class Select extends Query {
setCurrentRowNumber(0); setCurrentRowNumber(0);
Value[] previousKeyValues = null; Value[] previousKeyValues = null;
while (topTableFilter.next()) { while (topTableFilter.next()) {
checkCanceled();
setCurrentRowNumber(rowNumber + 1); setCurrentRowNumber(rowNumber + 1);
if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) { if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) {
rowNumber++; rowNumber++;
...@@ -306,7 +305,6 @@ public class Select extends Query { ...@@ -306,7 +305,6 @@ public class Select extends Query {
setCurrentRowNumber(0); setCurrentRowNumber(0);
ValueArray defaultGroup = ValueArray.get(new Value[0]); ValueArray defaultGroup = ValueArray.get(new Value[0]);
while (topTableFilter.next()) { while (topTableFilter.next()) {
checkCanceled();
setCurrentRowNumber(rowNumber + 1); setCurrentRowNumber(rowNumber + 1);
if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) { if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) {
Value key; Value key;
...@@ -457,7 +455,6 @@ public class Select extends Query { ...@@ -457,7 +455,6 @@ public class Select extends Query {
SearchRow first = null; SearchRow first = null;
int columnIndex = index.getColumns()[0].getColumnId(); int columnIndex = index.getColumns()[0].getColumnId();
while (true) { while (true) {
checkCanceled();
setCurrentRowNumber(rowNumber + 1); setCurrentRowNumber(rowNumber + 1);
Cursor cursor = index.findNext(session, first, null); Cursor cursor = index.findNext(session, first, null);
if (!cursor.next()) { if (!cursor.next()) {
...@@ -491,7 +488,6 @@ public class Select extends Query { ...@@ -491,7 +488,6 @@ public class Select extends Query {
int rowNumber = 0; int rowNumber = 0;
setCurrentRowNumber(0); setCurrentRowNumber(0);
while (topTableFilter.next()) { while (topTableFilter.next()) {
checkCanceled();
setCurrentRowNumber(rowNumber + 1); setCurrentRowNumber(rowNumber + 1);
if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) { if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) {
Value[] row = new Value[columnCount]; Value[] row = new Value[columnCount];
......
...@@ -85,7 +85,6 @@ public class Update extends Prepared { ...@@ -85,7 +85,6 @@ public class Update extends Prepared {
setCurrentRowNumber(0); setCurrentRowNumber(0);
int count = 0; int count = 0;
while (tableFilter.next()) { while (tableFilter.next()) {
checkCanceled();
setCurrentRowNumber(count+1); setCurrentRowNumber(count+1);
if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) { if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) {
Row oldRow = tableFilter.get(); Row oldRow = tableFilter.get();
...@@ -133,7 +132,6 @@ public class Update extends Prepared { ...@@ -133,7 +132,6 @@ public class Update extends Prepared {
if (table.fireRow()) { if (table.fireRow()) {
rows.invalidateCache(); rows.invalidateCache();
for (rows.reset(); rows.hasNext();) { for (rows.reset(); rows.hasNext();) {
checkCanceled();
Row o = rows.next(); Row o = rows.next();
Row n = rows.next(); Row n = rows.next();
table.fireAfterRow(session, o, n); table.fireAfterRow(session, o, n);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论