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

ANALYZE now uses less memory.

上级 7fc72e9d
...@@ -10,6 +10,7 @@ import java.util.ArrayList; ...@@ -10,6 +10,7 @@ import java.util.ArrayList;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.util.IntIntHashMap;
import org.h2.util.New; import org.h2.util.New;
import org.h2.util.ValueHashMap; import org.h2.util.ValueHashMap;
import org.h2.value.DataType; import org.h2.value.DataType;
...@@ -27,6 +28,7 @@ class AggregateData { ...@@ -27,6 +28,7 @@ class AggregateData {
private final int aggregateType; private final int aggregateType;
private final int dataType; private final int dataType;
private long count; private long count;
private IntIntHashMap distinctHashes;
private ValueHashMap<AggregateData> distinctValues; private ValueHashMap<AggregateData> distinctValues;
private Value value; private Value value;
private double sum, vpn; private double sum, vpn;
...@@ -47,15 +49,17 @@ class AggregateData { ...@@ -47,15 +49,17 @@ class AggregateData {
void add(Database database, boolean distinct, Value v) { void add(Database database, boolean distinct, Value v) {
if (aggregateType == Aggregate.SELECTIVITY) { if (aggregateType == Aggregate.SELECTIVITY) {
count++; count++;
if (distinctValues == null) { if (distinctHashes == null) {
distinctValues = ValueHashMap.newInstance(); distinctHashes = new IntIntHashMap();
} }
int size = distinctValues.size(); int size = distinctHashes.size();
if (size > Constants.SELECTIVITY_DISTINCT_COUNT) { if (size > Constants.SELECTIVITY_DISTINCT_COUNT) {
distinctValues = ValueHashMap.newInstance(); distinctHashes = new IntIntHashMap();
sum += size; sum += size;
} }
distinctValues.put(v, this); int hash = v.hashCode();
// the value -1 is not supported
distinctHashes.put(hash, 1);
return; return;
} }
if (aggregateType == Aggregate.COUNT_ALL) { if (aggregateType == Aggregate.COUNT_ALL) {
...@@ -168,7 +172,7 @@ class AggregateData { ...@@ -168,7 +172,7 @@ class AggregateData {
if (count == 0) { if (count == 0) {
s = 0; s = 0;
} else { } else {
sum += distinctValues.size(); sum += distinctHashes.size();
sum = 100 * sum / count; sum = 100 * sum / count;
s = (int) sum; s = (int) sum;
s = s <= 0 ? 1 : s > 100 ? 100 : s; s = s <= 0 ? 1 : s > 100 ? 100 : s;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论