提交 8f83bfd0 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 856033a1
...@@ -93,6 +93,16 @@ public class CompareLike extends Condition { ...@@ -93,6 +93,16 @@ public class CompareLike extends Condition {
} }
String pattern = r.getString(); String pattern = r.getString();
initPattern(pattern, getEscapeChar(e)); initPattern(pattern, getEscapeChar(e));
if ("%".equals(pattern)) {
// optimization for X LIKE '%': convert to X IS NOT NULL
return new Comparison(session, Comparison.IS_NOT_NULL, left, null).optimize(session);
}
if (isFullMatch()) {
// optimization for X LIKE 'Hello': convert to X = 'Hello'
Value value = ValueString.get(patternString);
Expression expr = ValueExpression.get(value);
return new Comparison(session, Comparison.EQUAL, left, expr).optimize(session);
}
isInit = true; isInit = true;
} }
return this; return this;
...@@ -211,9 +221,8 @@ public class CompareLike extends Condition { ...@@ -211,9 +221,8 @@ public class CompareLike extends Condition {
} }
private boolean compare(String s, int pi, int si) { private boolean compare(String s, int pi, int si) {
// TODO check if this is correct according to Unicode rules (code // TODO check if this is correct according to Unicode rules (code points)
// points) return compareMode.equalsChars(patternString, pi, s, si, ignoreCase);
return compareMode.compareString(patternString.substring(pi, pi + 1), s.substring(si, si + 1), ignoreCase) == 0;
} }
private boolean compareAt(String s, int pi, int si, int sLen) { private boolean compareAt(String s, int pi, int si, int sLen) {
...@@ -307,7 +316,19 @@ public class CompareLike extends Condition { ...@@ -307,7 +316,19 @@ public class CompareLike extends Condition {
types[i + 1] = ANY; types[i + 1] = ANY;
} }
} }
patternString = new String(pattern); patternString = new String(pattern, 0, patternLength);
}
private boolean isFullMatch() {
if (types == null) {
return false;
}
for (int i = 0; i < types.length; i++) {
if (types[i] != MATCH) {
return false;
}
}
return true;
} }
public void mapColumns(ColumnResolver resolver, int level) throws SQLException { public void mapColumns(ColumnResolver resolver, int level) throws SQLException {
......
...@@ -130,7 +130,7 @@ public class LogFile { ...@@ -130,7 +130,7 @@ public class LogFile {
buff.fill(size); buff.fill(size);
buff.setInt(0, blockCount); buff.setInt(0, blockCount);
buff.updateChecksum(); buff.updateChecksum();
// IOLogger.getInstance().logWrite(this.fileName, file.getFilePointer(), buff.length()); // IOLogger.getInstance().logWrite(this.fileName, file.getFilePointer(), buff.length());
if (rec != null) { if (rec != null) {
unwritten.add(rec); unwritten.add(rec);
} }
......
...@@ -93,12 +93,17 @@ public class SecureFileStore extends FileStore { ...@@ -93,12 +93,17 @@ public class SecureFileStore extends FileStore {
public void setLength(long newLength) throws SQLException { public void setLength(long newLength) throws SQLException {
long oldPos = pos; long oldPos = pos;
byte[] buff = new byte[Constants.FILE_BLOCK_SIZE];
long length = length(); long length = length();
if (newLength > length) { if (newLength > length) {
seek(length); seek(length);
for (long i = length; i < newLength; i += Constants.FILE_BLOCK_SIZE) { byte[] empty = EMPTY;
write(buff, 0, Constants.FILE_BLOCK_SIZE); while (true) {
int p = (int) Math.min(newLength - length, EMPTY.length);
if (p <= 0) {
break;
}
write(empty, 0, p);
length += p;
} }
seek(oldPos); seek(oldPos);
} else { } else {
......
...@@ -657,7 +657,7 @@ class WebThread extends Thread implements DatabaseEventListener { ...@@ -657,7 +657,7 @@ class WebThread extends Thread implements DatabaseEventListener {
return treeIndex; return treeIndex;
} }
boolean isOracle = schema.contents.isOracle; boolean isOracle = schema.contents.isOracle;
boolean showColumnTypes = tables.length < 100; boolean notManyTables = tables.length < 100;
for (int i = 0; i < tables.length; i++) { for (int i = 0; i < tables.length; i++) {
DbTableOrView table = tables[i]; DbTableOrView table = tables[i];
if (table.isView) { if (table.isView) {
...@@ -674,8 +674,8 @@ class WebThread extends Thread implements DatabaseEventListener { ...@@ -674,8 +674,8 @@ class WebThread extends Thread implements DatabaseEventListener {
treeIndex++; treeIndex++;
if (mainSchema) { if (mainSchema) {
StringBuffer columnsBuffer = new StringBuffer(); StringBuffer columnsBuffer = new StringBuffer();
treeIndex = addColumns(table, buff, treeIndex, showColumnTypes, columnsBuffer); treeIndex = addColumns(table, buff, treeIndex, notManyTables, columnsBuffer);
if (!isOracle) { if (!isOracle && notManyTables) {
treeIndex = addIndexes(meta, table.name, schema.name, buff, treeIndex); treeIndex = addIndexes(meta, table.name, schema.name, buff, treeIndex);
} }
buff.append("addTable('" + PageParser.escapeJavaScript(table.name) + "', '" buff.append("addTable('" + PageParser.escapeJavaScript(table.name) + "', '"
...@@ -699,7 +699,7 @@ class WebThread extends Thread implements DatabaseEventListener { ...@@ -699,7 +699,7 @@ class WebThread extends Thread implements DatabaseEventListener {
treeIndex++; treeIndex++;
if (mainSchema) { if (mainSchema) {
StringBuffer columnsBuffer = new StringBuffer(); StringBuffer columnsBuffer = new StringBuffer();
treeIndex = addColumns(view, buff, treeIndex, showColumnTypes, columnsBuffer); treeIndex = addColumns(view, buff, treeIndex, notManyTables, columnsBuffer);
if (schema.contents.isH2) { if (schema.contents.isH2) {
PreparedStatement prep = null; PreparedStatement prep = null;
try { try {
...@@ -736,10 +736,6 @@ class WebThread extends Thread implements DatabaseEventListener { ...@@ -736,10 +736,6 @@ class WebThread extends Thread implements DatabaseEventListener {
StringBuffer buff = new StringBuffer(); StringBuffer buff = new StringBuffer();
buff.append("setNode(0, 0, 0, 'database', '" + PageParser.escapeJavaScript((String) session.get("url")) buff.append("setNode(0, 0, 0, 'database', '" + PageParser.escapeJavaScript((String) session.get("url"))
+ "', null);\n"); + "', null);\n");
// String version = meta.getDatabaseProductName() + " " + meta.getDatabaseProductVersion();
// buff.append("setNode(1, 0, 0, 'info', '" + PageParser.escapeJavaScript(version)+ "', null);\n");
//
// int treeIndex = 2;
int treeIndex = 1; int treeIndex = 1;
DbSchema defaultSchema = contents.defaultSchema; DbSchema defaultSchema = contents.defaultSchema;
......
...@@ -26,7 +26,7 @@ import org.h2.util.TempFileDeleter; ...@@ -26,7 +26,7 @@ import org.h2.util.TempFileDeleter;
public class FileStore { public class FileStore {
public static final int HEADER_LENGTH = 3 * Constants.FILE_BLOCK_SIZE; public static final int HEADER_LENGTH = 3 * Constants.FILE_BLOCK_SIZE;
private static final byte[] EMPTY = new byte[16 * 1024]; protected static final byte[] EMPTY = new byte[16 * 1024];
protected String name; protected String name;
protected DataHandler handler; protected DataHandler handler;
...@@ -240,14 +240,7 @@ public class FileStore { ...@@ -240,14 +240,7 @@ public class FileStore {
return true; return true;
} }
public void setLength(long newLength) throws SQLException { private void extendByWriting(long newLength) throws IOException {
if (SysProperties.CHECK && newLength % Constants.FILE_BLOCK_SIZE != 0) {
throw Message.getInternalError("unaligned setLength " + name + " pos " + newLength);
}
checkPowerOff();
checkWritingAllowed();
try {
if (synchronousMode && newLength > fileLength) {
long pos = filePos; long pos = filePos;
file.seek(fileLength); file.seek(fileLength);
byte[] empty = EMPTY; byte[] empty = EMPTY;
...@@ -260,6 +253,17 @@ public class FileStore { ...@@ -260,6 +253,17 @@ public class FileStore {
fileLength += p; fileLength += p;
} }
file.seek(pos); file.seek(pos);
}
public void setLength(long newLength) throws SQLException {
if (SysProperties.CHECK && newLength % Constants.FILE_BLOCK_SIZE != 0) {
throw Message.getInternalError("unaligned setLength " + name + " pos " + newLength);
}
checkPowerOff();
checkWritingAllowed();
try {
if (synchronousMode && newLength > fileLength) {
extendByWriting(newLength);
} else { } else {
file.setLength(newLength); file.setLength(newLength);
} }
......
...@@ -24,6 +24,19 @@ public class CompareMode { ...@@ -24,6 +24,19 @@ public class CompareMode {
this.name = name == null ? OFF : name; this.name = name == null ? OFF : name;
} }
public boolean equalsChars(String a, int ai, String b, int bi, boolean ignoreCase) {
if (collator != null) {
return compareString(a.substring(ai, ai + 1), b.substring(bi, bi + 1), ignoreCase) == 0;
}
char ca = a.charAt(ai);
char cb = b.charAt(bi);
if (ignoreCase) {
ca = Character.toUpperCase(ca);
cb = Character.toUpperCase(cb);
}
return ca == cb;
}
public int compareString(String a, String b, boolean ignoreCase) { public int compareString(String a, String b, boolean ignoreCase) {
if (collator == null) { if (collator == null) {
if (ignoreCase) { if (ignoreCase) {
......
...@@ -32,7 +32,8 @@ I am sorry to say that, but it looks like a corruption problem. I am very intere ...@@ -32,7 +32,8 @@ I am sorry to say that, but it looks like a corruption problem. I am very intere
- The second workarounds is: delete the index.db file (it is re-created automatically) and try again. Does it work when you do this? - The second workarounds is: delete the index.db file (it is re-created automatically) and try again. Does it work when you do this?
- The third workarounds is: use the tool org.h2.tools.Recover to create the SQL script file, and then re-create the database using this script. Does it work when you do this? - The third workarounds is: use the tool org.h2.tools.Recover to create the SQL script file, and then re-create the database using this script. Does it work when you do this?
- Do you use any settings or special features (for example, the setting LOG=0, or two phase commit, linked tables, cache settings)? - Do you use any settings or special features (for example, the setting LOG=0, or two phase commit, linked tables, cache settings)?
- On what operating system, file system, and virtual machine? - Is the application multi-threaded?
- On what operating system, file system, and virtual machine (java -version)?
- How big is the database? - How big is the database?
- Is the database usually closed normally, or is process terminated forcefully or the computer switched off? - Is the database usually closed normally, or is process terminated forcefully or the computer switched off?
- Is it possible to reproduce this problem using a fresh database (sometimes, or always)? - Is it possible to reproduce this problem using a fresh database (sometimes, or always)?
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论