提交 273167ab authored 作者: Thomas Mueller's avatar Thomas Mueller

New system property h2.analyzeAuto.

上级 6bb3ea33
......@@ -9,6 +9,7 @@ package org.h2.command.ddl;
import org.h2.command.Prepared;
import org.h2.constant.SysProperties;
import org.h2.engine.Database;
import org.h2.engine.Right;
import org.h2.engine.Session;
import org.h2.result.ResultInterface;
import org.h2.table.Column;
......@@ -54,17 +55,22 @@ public class Analyze extends DefineCommand {
if (!(table instanceof RegularTable) || table.isHidden() || session == null) {
return;
}
if (!manual) {
if (session.getDatabase().isSysTableLocked()) {
return;
}
if (table.hasSelectTrigger()) {
return;
}
}
if (table.isTemporary() && !table.isGlobalTemporary()
&& session.findLocalTempTable(table.getName()) == null) {
return;
}
if (!manual && table.hasSelectTrigger()) {
if (table.isLockedExclusively() && !table.isLockedExclusivelyBy(session)) {
return;
}
if (table.isLockedExclusively() && !table.isLockedExclusivelyBy(session)) {
if (!session.getUser().hasRight(table, Right.SELECT)) {
return;
}
Database db = session.getDatabase();
......
......@@ -91,19 +91,32 @@ public class User extends RightOwner {
* @throws SQLException if this user does not have the required rights
*/
public void checkRight(Table table, int rightMask) {
if (!hasRight(table, rightMask)) {
throw DbException.get(ErrorCode.NOT_ENOUGH_RIGHTS_FOR_1, table.getSQL());
}
}
/**
* See if this user has the given rights for this database object.
*
* @param table the database object
* @param rightMask the rights required
* @return true if the user has the rights
*/
public boolean hasRight(Table table, int rightMask) {
if (rightMask != Right.SELECT && !systemUser) {
table.checkWritingAllowed();
}
if (admin) {
return;
return true;
}
Role publicRole = database.getPublicRole();
if (publicRole.isRightGrantedRecursive(table, rightMask)) {
return;
return true;
}
if (table instanceof MetaTable || table instanceof RangeTable) {
// everybody has access to the metadata information
return;
return true;
}
String tableType = table.getTableType();
if (Table.VIEW.equals(tableType)) {
......@@ -111,19 +124,20 @@ public class User extends RightOwner {
if (v.getOwner() == this) {
// the owner of a view has access:
// SELECT * FROM (SELECT * FROM ...)
return;
return true;
}
} else if (tableType == null) {
// function table
return;
return true;
}
if (!isRightGrantedRecursive(table, rightMask)) {
if (table.isTemporary() && !table.isGlobalTemporary()) {
// the owner has all rights on local temporary tables
return;
return true;
}
throw DbException.get(ErrorCode.NOT_ENOUGH_RIGHTS_FOR_1, table.getSQL());
if (isRightGrantedRecursive(table, rightMask)) {
return true;
}
return false;
}
/**
......
......@@ -22,6 +22,7 @@ import java.sql.Types;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.LinkedList;
import org.h2.constant.SysProperties;
import org.h2.jdbc.JdbcConnection;
import org.h2.message.TraceSystem;
import org.h2.store.FileLock;
......@@ -1080,6 +1081,10 @@ public abstract class TestBase {
* @throws AssertionError if the databases don't match
*/
protected void assertEqualDatabases(Statement stat1, Statement stat2) throws SQLException {
if (SysProperties.ANALYZE_AUTO > 0) {
stat1.execute("analyze");
stat2.execute("analyze");
}
ResultSet rs1 = stat1.executeQuery("SCRIPT NOPASSWORDS");
ResultSet rs2 = stat2.executeQuery("SCRIPT NOPASSWORDS");
ArrayList<String> list1 = new ArrayList<String>();
......
......@@ -16,6 +16,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;
import java.util.TreeSet;
import org.h2.constant.SysProperties;
import org.h2.test.TestBase;
import org.h2.tools.SimpleResultSet;
import org.h2.util.New;
......@@ -36,6 +37,7 @@ public class TestOptimizations extends TestBase {
}
public void test() throws Exception {
testAutoAnalyze();
testInAndBetween();
testNestedIn();
testNestedInSelectAndLike();
......@@ -59,6 +61,24 @@ public class TestOptimizations extends TestBase {
deleteDb("optimizations");
}
private void testAutoAnalyze() throws SQLException {
int auto = SysProperties.ANALYZE_AUTO;
if (auto == 0) {
return;
}
deleteDb("optimizations");
Connection conn = getConnection("optimizations");
Statement stat = conn.createStatement();
stat.execute("create table test(id int)");
stat.execute("create user onlyInsert password ''");
stat.execute("grant insert on test to onlyInsert");
Connection conn2 = getConnection("optimizations", "onlyInsert", getPassword(""));
Statement stat2 = conn2.createStatement();
stat2.execute("insert into test select x from system_range(1, " + (auto + 10) + ")");
conn.close();
conn2.close();
}
private void testInAndBetween() throws SQLException {
deleteDb("optimizations");
Connection conn = getConnection("optimizations");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论