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

--no commit message

--no commit message
上级 4b0fe6a5
......@@ -547,14 +547,6 @@ public class Select extends Query {
}
}
cost = preparePlan();
if (sort != null && !isQuickQuery && !isGroupQuery && !distinct) {
Index index = getSortIndex();
Index current = topTableFilter.getIndex();
if (index != null && (current.getIndexType().isScan() || current == index)) {
topTableFilter.setIndex(index);
sortUsingIndex = true;
}
}
if (SysProperties.OPTIMIZE_DISTINCT && distinct && !isGroupQuery && filters.size() == 1 && expressions.size() == 1 && condition == null) {
Expression expr = (Expression) expressions.get(0);
expr = expr.getNonAliasExpression();
......@@ -578,6 +570,14 @@ public class Select extends Query {
}
}
}
if (sort != null && !isQuickQuery && !isGroupQuery && (!distinct || isDistinctQuery)) {
Index index = getSortIndex();
Index current = topTableFilter.getIndex();
if (index != null && (current.getIndexType().isScan() || current == index)) {
topTableFilter.setIndex(index);
sortUsingIndex = true;
}
}
}
public double getCost() {
......
......@@ -149,8 +149,7 @@ java org.h2.test.TestAll timer
/*
(code coverage: limit, sample-size)
add tests with select distinct type
check no more @author
staging.trace.db.gz
......
......@@ -70,6 +70,18 @@ public class TestOptimizations extends TestBase {
check(i, rs.getInt(1));
}
checkFalse(rs.next());
rs = stat.executeQuery("SELECT DISTINCT TYPE FROM TEST ORDER BY TYPE LIMIT 5 OFFSET 2");
for (int i = 2; i < 7; i++) {
rs.next();
check(i, rs.getInt(1));
}
checkFalse(rs.next());
rs = stat.executeQuery("SELECT DISTINCT TYPE FROM TEST ORDER BY TYPE LIMIT 0 OFFSET 0 SAMPLE_SIZE 3");
for (int i = 0; i < 3; i++) {
rs.next();
check(i, rs.getInt(1));
}
checkFalse(rs.next());
conn.close();
}
......
/*
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.unit;
......@@ -21,6 +21,9 @@ import org.h2.util.IOUtils;
import org.h2.util.NetUtils;
import org.h2.util.StringUtils;
/**
* A simple standalone FTP client.
*/
public class FtpClient {
private Socket socket;
private BufferedReader reader;
......@@ -30,13 +33,13 @@ public class FtpClient {
private Socket socketData;
private InputStream inData;
private OutputStream outData;
public static FtpClient open(String url) throws SQLException, IOException {
FtpClient client = new FtpClient();
client.connect(url);
return client;
}
private FtpClient() {
}
......@@ -48,7 +51,7 @@ public class FtpClient {
writer = new PrintWriter(new OutputStreamWriter(out, Constants.UTF8));
readCode(220);
}
private void readLine() throws IOException {
message = reader.readLine();
int idx = message.indexOf(' ');
......@@ -59,26 +62,26 @@ public class FtpClient {
message = message.substring(idx + 1);
}
}
private void readCode(int expected) throws IOException {
readLine();
if (code != expected) {
throw new IOException("Expected: " + expected + " got: " + message);
}
}
private void send(String command) throws IOException {
writer.println(command);
writer.flush();
}
public void login(String userName, String password) throws IOException {
send("USER " + userName);
readCode(331);
send("PASS " + password);
readCode(230);
send("SYST");
readCode(215);
readCode(215);
send("SITE");
readCode(500);
send("STRU F");
......@@ -86,7 +89,7 @@ public class FtpClient {
send("TYPE I");
readCode(200);
}
public void close() throws IOException {
if (socket != null) {
send("QUIT");
......@@ -94,7 +97,7 @@ public class FtpClient {
socket.close();
}
}
public void changeWorkingDirectory(String dir) throws IOException {
send("CWD " + dir);
readCode(250);
......@@ -122,7 +125,7 @@ public class FtpClient {
public void modificationTime(String fileName) throws IOException {
send("MDTM " + fileName);
readCode(213);
}
......@@ -136,7 +139,7 @@ public class FtpClient {
readCode(257);
return removeQuotes();
}
private String removeQuotes() {
int first = message.indexOf('"') + 1;
int last = message.lastIndexOf('"');
......@@ -150,7 +153,7 @@ public class FtpClient {
}
return buff.toString();
}
private void passive() throws IOException, SQLException {
send("PASV");
readCode(227);
......@@ -171,14 +174,14 @@ public class FtpClient {
inData = socketData.getInputStream();
outData = socketData.getOutputStream();
}
public void rename(String fromFileName, String toFileName) throws IOException {
send("RNFR " + fromFileName);
readCode(350);
send("RNTO " + toFileName);
readCode(250);
}
public void retrieve(String fileName, OutputStream out, long restartAt) throws IOException, SQLException {
passive();
if (restartAt > 0) {
......@@ -194,14 +197,14 @@ public class FtpClient {
send("RMD " + dir);
readCode(250);
}
public long size(String fileName) throws IOException {
send("SIZE " + fileName);
readCode(250);
long size = Long.parseLong(message);
return size;
}
public void store(String fileName, InputStream in) throws IOException, SQLException {
passive();
send("STOR " + fileName);
......@@ -209,7 +212,7 @@ public class FtpClient {
IOUtils.copyAndClose(in, outData);
readCode(226);
}
public String nameList(String dir) throws IOException, SQLException {
passive();
send("NLST " + dir);
......
/*
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.unit;
......@@ -11,9 +11,8 @@ import org.h2.test.TestBase;
import org.h2.util.BitField;
/**
* @author Thomas
* A unit test for bit fields.
*/
public class TestBitField extends TestBase {
public void test() throws Exception {
......
......@@ -11,6 +11,9 @@ import java.util.Random;
import org.h2.test.TestBase;
/**
* Tests the cache.
*/
public class TestCache extends TestBase {
public void test() throws Exception {
......
......@@ -9,66 +9,10 @@ import java.util.Random;
import org.h2.test.TestBase;
import org.h2.tools.CompressTool;
/**
* Data compression tests.
*/
public class TestCompress extends TestBase {
public static void main(String[] a) throws Exception {
byte[] data = new byte[1000];
long total = 0;
for (int i = 100; i < 104; i++) {
long time = System.currentTimeMillis();
for (int j = 0; j < 10000000; j++) {
// System.arraycopy(data, 0, data, 100, 11);
// for (int k = 0, n = 100; k < 11; k++) {
// data[k] = data[n++];
// }
int outPos = 0, ctrl = 100, len = i;
// do {
// switch((len - outPos) & 7) {
// case 0:
// data[outPos] = data[outPos++ + ctrl];
// case 7:
// data[outPos] = data[outPos++ + ctrl];
// case 6:
// data[outPos] = data[outPos++ + ctrl];
// case 5:
// data[outPos] = data[outPos++ + ctrl];
// case 4:
// data[outPos] = data[outPos++ + ctrl];
// case 3:
// data[outPos] = data[outPos++ + ctrl];
// case 2:
// data[outPos] = data[outPos++ + ctrl];
// case 1:
// data[outPos] = data[outPos++ + ctrl];
// }
// } while(outPos < len);
//
data[outPos] = data[outPos++ + ctrl];
data[outPos] = data[outPos++ + ctrl];
while (outPos < len - 8) {
data[outPos] = data[outPos++ + ctrl];
data[outPos] = data[outPos++ + ctrl];
data[outPos] = data[outPos++ + ctrl];
data[outPos] = data[outPos++ + ctrl];
data[outPos] = data[outPos++ + ctrl];
data[outPos] = data[outPos++ + ctrl];
data[outPos] = data[outPos++ + ctrl];
data[outPos] = data[outPos++ + ctrl];
}
while (outPos < len) {
data[outPos] = data[outPos++ + ctrl];
}
}
// now: 8907/11859, switch: 9078/14782
long t = (System.currentTimeMillis() - time);
total += t;
System.out.println("i: " + i + " time: " + t);
}
System.out.println("total: " + total);
}
public void test() throws Exception {
if (config.big) {
......
/*
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.unit;
......@@ -18,9 +18,8 @@ import org.h2.value.ValueNull;
import org.h2.value.ValueString;
/**
* @author Thomas
* Data page tests.
*/
public class TestDataPage extends TestBase implements DataHandler {
boolean text;
......
......@@ -11,6 +11,12 @@ import org.h2.test.TestBase;
import org.h2.util.DateTimeUtils;
import org.h2.value.Value;
/**
* Tests the data parsing.
* The problem is that some dates are not allowed because of the summer time change.
* Most countries change at 2 o'clock in the morning to 3 o'clock, but some
* (for example Chile) change at midnight. Non-lenient parsing wouldn't work in this case.
*/
public class TestDate extends TestBase {
public void test() throws Exception {
......
......@@ -13,6 +13,10 @@ import java.sql.SQLException;
import org.h2.api.DatabaseEventListener;
import org.h2.test.TestBase;
/**
* Tests the flag db_close_on_exit.
* A new process is started.
*/
public class TestExit extends TestBase implements DatabaseEventListener {
public void test() throws Exception {
......
......@@ -12,13 +12,16 @@ import org.h2.test.TestBase;
import org.h2.util.FileUtils;
import org.h2.value.Value;
/**
* Tests the in-memory file system.
*/
public class TestFile extends TestBase implements DataHandler {
public void test() throws Exception {
doTest(false);
doTest(true);
}
private void doTest(boolean compress) throws Exception {
byte[] magic = new byte[0];
int len = getSize(1000, 10000);
......
......@@ -11,7 +11,8 @@ import org.h2.store.FileLock;
import org.h2.test.TestBase;
/**
* @author Thomas
* Tests the database file locking facility.
* Both lock files and sockets locking is tested.
*/
public class TestFileLock extends TestBase implements Runnable {
......
......@@ -19,6 +19,9 @@ import org.h2.store.fs.FileObject;
import org.h2.store.fs.FileSystem;
import org.h2.test.TestBase;
/**
* Tests various file system.
*/
public class TestFileSystem extends TestBase {
public void test() throws Exception {
......
......@@ -10,6 +10,9 @@ import org.h2.server.ftp.FtpServer;
import org.h2.test.TestBase;
import org.h2.tools.Server;
/**
* Tests the FTP server tool.
*/
public class TestFtp extends TestBase implements FtpEventListener {
private FtpEvent lastEvent;
......
......@@ -9,6 +9,9 @@ import java.util.Random;
import org.h2.test.TestBase;
import org.h2.util.IntArray;
/**
* Tests the IntArray class.
*/
public class TestIntArray extends TestBase {
public void test() throws Exception {
......
......@@ -9,6 +9,9 @@ import java.util.Random;
import org.h2.test.TestBase;
import org.h2.util.IntIntHashMap;
/**
* Tests the IntHashMap class.
*/
public class TestIntIntHashMap extends TestBase {
Random rand = new Random();
......
......@@ -11,13 +11,16 @@ import java.sql.SQLException;
import org.h2.test.TestBase;
/**
* Tests the multi-threaded kernel feature.
*/
public class TestMultiThreadedKernel extends TestBase implements Runnable {
private String url, user, password;
private int id;
private TestMultiThreadedKernel master;
private volatile boolean stop;
public void test() throws Exception {
if (config.networked) {
return;
......@@ -43,7 +46,7 @@ public class TestMultiThreadedKernel extends TestBase implements Runnable {
list[i].join();
}
}
public void run() {
try {
org.h2.Driver.load();
......
......@@ -14,6 +14,10 @@ import org.h2.test.TestBase;
import org.h2.value.Value;
import org.h2.value.ValueString;
/**
* Tests numeric overflow on various data types.
* Other than in Java, overflow is detected and an exception is thrown.
*/
public class TestOverflow extends TestBase {
public void test() throws Exception {
......
/*
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.unit;
......@@ -9,7 +9,7 @@ import org.h2.test.TestBase;
import org.h2.value.CompareMode;
/**
* @author Thomas
* Tests LIKE pattern matching.
*/
public class TestPattern extends TestBase {
......
......@@ -12,6 +12,9 @@ import java.io.StringReader;
import org.h2.test.TestBase;
import org.h2.util.IOUtils;
/**
* Tests the stream to UTF-8 reader conversion.
*/
public class TestReader extends TestBase {
public void test() throws Exception {
......
......@@ -12,6 +12,9 @@ import org.h2.test.TestBase;
import org.h2.tools.DeleteDbFiles;
import org.h2.util.StringUtils;
/**
* Tests the sample apps.
*/
public class TestSampleApps extends TestBase {
public void test() throws Exception {
......
......@@ -10,6 +10,9 @@ import java.util.Random;
import org.h2.test.TestBase;
import org.h2.util.ScriptReader;
/**
* Tests the script reader tool that breaks up SQL scripts in statements.
*/
public class TestScriptReader extends TestBase {
public void test() throws Exception {
......
/*
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.unit;
......@@ -11,9 +11,8 @@ import org.h2.test.TestBase;
import org.h2.util.ByteUtils;
/**
* @author Thomas
* Tests various security primitives.
*/
public class TestSecurity extends TestBase {
public void test() throws Exception {
......
......@@ -12,6 +12,9 @@ import org.h2.compress.LZFInputStream;
import org.h2.compress.LZFOutputStream;
import org.h2.test.TestBase;
/**
* Tests the LZF stream.
*/
public class TestStreams extends TestBase {
public void test() throws Exception {
......
......@@ -9,6 +9,9 @@ import java.util.Random;
import org.h2.test.TestBase;
import org.h2.util.StringCache;
/**
* Tests the string cache facility.
*/
public class TestStringCache extends TestBase {
public static void main(String[] args) throws Exception {
......
......@@ -12,6 +12,9 @@ import java.util.Random;
import org.h2.test.TestBase;
import org.h2.util.StringUtils;
/**
* Tests string utility methods.
*/
public class TestStringUtils extends TestBase {
public void test() throws Exception {
......
......@@ -30,6 +30,9 @@ import org.h2.tools.Script;
import org.h2.tools.Server;
import org.h2.util.Resources;
/**
* Tests the database tools.
*/
public class TestTools extends TestBase {
private Server server;
......
......@@ -7,12 +7,15 @@ package org.h2.test.unit;
import org.h2.test.TestBase;
import org.h2.value.ValueUuid;
/**
* Tests features of values.
*/
public class TestValue extends TestBase {
public void test() throws Exception {
testUUID();
}
private void testUUID() throws Exception {
long maxHigh = 0, maxLow = 0, minHigh = -1L, minLow = -1L;
for (int i = 0; i < 100; i++) {
......
......@@ -18,6 +18,9 @@ import org.h2.value.CompareMode;
import org.h2.value.Value;
import org.h2.value.ValueInt;
/**
* Tests the value hash map.
*/
public class TestValueHashMap extends TestBase implements DataHandler {
CompareMode compareMode = new CompareMode(null, null);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论