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

--no commit message

--no commit message
上级 856033a1
......@@ -93,6 +93,16 @@ public class CompareLike extends Condition {
}
String pattern = r.getString();
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;
}
return this;
......@@ -211,9 +221,8 @@ public class CompareLike extends Condition {
}
private boolean compare(String s, int pi, int si) {
// TODO check if this is correct according to Unicode rules (code
// points)
return compareMode.compareString(patternString.substring(pi, pi + 1), s.substring(si, si + 1), ignoreCase) == 0;
// TODO check if this is correct according to Unicode rules (code points)
return compareMode.equalsChars(patternString, pi, s, si, ignoreCase);
}
private boolean compareAt(String s, int pi, int si, int sLen) {
......@@ -307,7 +316,19 @@ public class CompareLike extends Condition {
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 {
......
......@@ -130,7 +130,7 @@ public class LogFile {
buff.fill(size);
buff.setInt(0, blockCount);
buff.updateChecksum();
// IOLogger.getInstance().logWrite(this.fileName, file.getFilePointer(), buff.length());
// IOLogger.getInstance().logWrite(this.fileName, file.getFilePointer(), buff.length());
if (rec != null) {
unwritten.add(rec);
}
......
......@@ -93,12 +93,17 @@ public class SecureFileStore extends FileStore {
public void setLength(long newLength) throws SQLException {
long oldPos = pos;
byte[] buff = new byte[Constants.FILE_BLOCK_SIZE];
long length = length();
if (newLength > length) {
seek(length);
for (long i = length; i < newLength; i += Constants.FILE_BLOCK_SIZE) {
write(buff, 0, Constants.FILE_BLOCK_SIZE);
byte[] empty = EMPTY;
while (true) {
int p = (int) Math.min(newLength - length, EMPTY.length);
if (p <= 0) {
break;
}
write(empty, 0, p);
length += p;
}
seek(oldPos);
} else {
......
......@@ -657,7 +657,7 @@ class WebThread extends Thread implements DatabaseEventListener {
return treeIndex;
}
boolean isOracle = schema.contents.isOracle;
boolean showColumnTypes = tables.length < 100;
boolean notManyTables = tables.length < 100;
for (int i = 0; i < tables.length; i++) {
DbTableOrView table = tables[i];
if (table.isView) {
......@@ -674,8 +674,8 @@ class WebThread extends Thread implements DatabaseEventListener {
treeIndex++;
if (mainSchema) {
StringBuffer columnsBuffer = new StringBuffer();
treeIndex = addColumns(table, buff, treeIndex, showColumnTypes, columnsBuffer);
if (!isOracle) {
treeIndex = addColumns(table, buff, treeIndex, notManyTables, columnsBuffer);
if (!isOracle && notManyTables) {
treeIndex = addIndexes(meta, table.name, schema.name, buff, treeIndex);
}
buff.append("addTable('" + PageParser.escapeJavaScript(table.name) + "', '"
......@@ -699,7 +699,7 @@ class WebThread extends Thread implements DatabaseEventListener {
treeIndex++;
if (mainSchema) {
StringBuffer columnsBuffer = new StringBuffer();
treeIndex = addColumns(view, buff, treeIndex, showColumnTypes, columnsBuffer);
treeIndex = addColumns(view, buff, treeIndex, notManyTables, columnsBuffer);
if (schema.contents.isH2) {
PreparedStatement prep = null;
try {
......@@ -736,10 +736,6 @@ class WebThread extends Thread implements DatabaseEventListener {
StringBuffer buff = new StringBuffer();
buff.append("setNode(0, 0, 0, 'database', '" + PageParser.escapeJavaScript((String) session.get("url"))
+ "', 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;
DbSchema defaultSchema = contents.defaultSchema;
......
......@@ -26,7 +26,7 @@ import org.h2.util.TempFileDeleter;
public class FileStore {
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 DataHandler handler;
......@@ -46,7 +46,7 @@ public class FileStore {
public static FileStore open(DataHandler handler, String name, String mode, byte[] magic, String cipher, byte[] key) throws SQLException {
return open(handler, name, mode, magic, cipher, key, Constants.ENCRYPTION_KEY_HASH_ITERATIONS);
}
public static FileStore open(DataHandler handler, String name, String mode, byte[] magic, String cipher,
byte[] key, int keyIterations) throws SQLException {
FileStore store;
......@@ -92,7 +92,7 @@ public class FileStore {
protected void initKey(byte[] salt) {
// do nothing
}
public void setCheckedWriting(boolean value) {
this.checkedWriting = value;
}
......@@ -240,6 +240,21 @@ public class FileStore {
return true;
}
private void extendByWriting(long newLength) throws IOException {
long pos = filePos;
file.seek(fileLength);
byte[] empty = EMPTY;
while (true) {
int p = (int) Math.min(newLength - fileLength, EMPTY.length);
if (p <= 0) {
break;
}
file.write(empty, 0, p);
fileLength += p;
}
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);
......@@ -248,18 +263,7 @@ public class FileStore {
checkWritingAllowed();
try {
if (synchronousMode && newLength > fileLength) {
long pos = filePos;
file.seek(fileLength);
byte[] empty = EMPTY;
while (true) {
int p = (int) Math.min(newLength - fileLength, EMPTY.length);
if (p <= 0) {
break;
}
file.write(empty, 0, p);
fileLength += p;
}
file.seek(pos);
extendByWriting(newLength);
} else {
file.setLength(newLength);
}
......@@ -343,11 +347,11 @@ public class FileStore {
file.seek(filePos);
}
}
private static void trace(String method, String fileName, Object o) {
if (SysProperties.TRACE_IO) {
System.out.println("FileStore." + method + " " + fileName + " " + o);
}
}
}
}
......@@ -14,7 +14,7 @@ import org.h2.util.FileUtils;
*/
public class FileObjectDisk implements FileObject {
private RandomAccessFile file;
FileObjectDisk(RandomAccessFile file) {
this.file = file;
}
......@@ -42,11 +42,11 @@ public class FileObjectDisk implements FileObject {
public long getFilePointer() throws IOException {
return file.getFilePointer();
}
public void sync() throws IOException {
file.getFD().sync();
}
public void setLength(long newLength) throws IOException {
FileUtils.setLength(file, newLength);
}
......
......@@ -24,6 +24,19 @@ public class CompareMode {
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) {
if (collator == null) {
if (ignoreCase) {
......
......@@ -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 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)?
- 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?
- 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)?
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论