提交 1654119e authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Remove DataType.memory

上级 0dcbcac1
...@@ -163,11 +163,6 @@ public class DataType { ...@@ -163,11 +163,6 @@ public class DataType {
*/ */
public boolean hidden; public boolean hidden;
/**
* The number of bytes required for an object.
*/
public int memory;
static { static {
Class<?> g; Class<?> g;
try { try {
...@@ -182,77 +177,59 @@ public class DataType { ...@@ -182,77 +177,59 @@ public class DataType {
dataType.defaultPrecision = dataType.maxPrecision = ValueNull.PRECISION; dataType.defaultPrecision = dataType.maxPrecision = ValueNull.PRECISION;
add(Value.NULL, Types.NULL, add(Value.NULL, Types.NULL,
dataType, dataType,
new String[]{"NULL"}, new String[]{"NULL"}
// the value is always in the cache
0
); );
add(Value.STRING, Types.VARCHAR, add(Value.STRING, Types.VARCHAR,
createString(true), createString(true),
new String[]{"VARCHAR", "CHARACTER VARYING", "VARCHAR2", "NVARCHAR", "NVARCHAR2", new String[]{"VARCHAR", "CHARACTER VARYING", "VARCHAR2", "NVARCHAR", "NVARCHAR2",
"VARCHAR_CASESENSITIVE", "TID"}, "VARCHAR_CASESENSITIVE", "TID"}
// 24 for ValueString, 24 for String
48
); );
add(Value.STRING, Types.LONGVARCHAR, add(Value.STRING, Types.LONGVARCHAR,
createString(true), createString(true),
new String[]{"LONGVARCHAR", "LONGNVARCHAR"}, new String[]{"LONGVARCHAR", "LONGNVARCHAR"}
48
); );
add(Value.STRING_FIXED, Types.CHAR, add(Value.STRING_FIXED, Types.CHAR,
createString(true), createString(true),
new String[]{"CHAR", "CHARACTER", "NCHAR"}, new String[]{"CHAR", "CHARACTER", "NCHAR"}
48
); );
add(Value.STRING_IGNORECASE, Types.VARCHAR, add(Value.STRING_IGNORECASE, Types.VARCHAR,
createString(false), createString(false),
new String[]{"VARCHAR_IGNORECASE"}, new String[]{"VARCHAR_IGNORECASE"}
48
); );
add(Value.BOOLEAN, Types.BOOLEAN, add(Value.BOOLEAN, Types.BOOLEAN,
createDecimal(ValueBoolean.PRECISION, ValueBoolean.PRECISION, createDecimal(ValueBoolean.PRECISION, ValueBoolean.PRECISION,
0, ValueBoolean.DISPLAY_SIZE, false, false), 0, ValueBoolean.DISPLAY_SIZE, false, false),
new String[]{"BOOLEAN", "BIT", "BOOL"}, new String[]{"BOOLEAN", "BIT", "BOOL"}
// the value is always in the cache
0
); );
add(Value.BYTE, Types.TINYINT, add(Value.BYTE, Types.TINYINT,
createDecimal(ValueByte.PRECISION, ValueByte.PRECISION, 0, createDecimal(ValueByte.PRECISION, ValueByte.PRECISION, 0,
ValueByte.DISPLAY_SIZE, false, false), ValueByte.DISPLAY_SIZE, false, false),
new String[]{"TINYINT"}, new String[]{"TINYINT"}
// the value is almost always in the cache
1
); );
add(Value.SHORT, Types.SMALLINT, add(Value.SHORT, Types.SMALLINT,
createDecimal(ValueShort.PRECISION, ValueShort.PRECISION, 0, createDecimal(ValueShort.PRECISION, ValueShort.PRECISION, 0,
ValueShort.DISPLAY_SIZE, false, false), ValueShort.DISPLAY_SIZE, false, false),
new String[]{"SMALLINT", "YEAR", "INT2"}, new String[]{"SMALLINT", "YEAR", "INT2"}
// in many cases the value is in the cache
20
); );
add(Value.INT, Types.INTEGER, add(Value.INT, Types.INTEGER,
createDecimal(ValueInt.PRECISION, ValueInt.PRECISION, 0, createDecimal(ValueInt.PRECISION, ValueInt.PRECISION, 0,
ValueInt.DISPLAY_SIZE, false, false), ValueInt.DISPLAY_SIZE, false, false),
new String[]{"INTEGER", "INT", "MEDIUMINT", "INT4", "SIGNED"}, new String[]{"INTEGER", "INT", "MEDIUMINT", "INT4", "SIGNED"}
// in many cases the value is in the cache
20
); );
add(Value.INT, Types.INTEGER, add(Value.INT, Types.INTEGER,
createDecimal(ValueInt.PRECISION, ValueInt.PRECISION, 0, createDecimal(ValueInt.PRECISION, ValueInt.PRECISION, 0,
ValueInt.DISPLAY_SIZE, false, true), ValueInt.DISPLAY_SIZE, false, true),
new String[]{"SERIAL"}, new String[]{"SERIAL"}
20
); );
add(Value.LONG, Types.BIGINT, add(Value.LONG, Types.BIGINT,
createDecimal(ValueLong.PRECISION, ValueLong.PRECISION, 0, createDecimal(ValueLong.PRECISION, ValueLong.PRECISION, 0,
ValueLong.DISPLAY_SIZE, false, false), ValueLong.DISPLAY_SIZE, false, false),
new String[]{"BIGINT", "INT8", "LONG"}, new String[]{"BIGINT", "INT8", "LONG"}
24
); );
add(Value.LONG, Types.BIGINT, add(Value.LONG, Types.BIGINT,
createDecimal(ValueLong.PRECISION, ValueLong.PRECISION, 0, createDecimal(ValueLong.PRECISION, ValueLong.PRECISION, 0,
ValueLong.DISPLAY_SIZE, false, true), ValueLong.DISPLAY_SIZE, false, true),
new String[]{"IDENTITY", "BIGSERIAL"}, new String[]{"IDENTITY", "BIGSERIAL"}
24
); );
if (SysProperties.BIG_DECIMAL_IS_DECIMAL) { if (SysProperties.BIG_DECIMAL_IS_DECIMAL) {
addDecimal(); addDecimal();
...@@ -264,42 +241,33 @@ public class DataType { ...@@ -264,42 +241,33 @@ public class DataType {
add(Value.FLOAT, Types.REAL, add(Value.FLOAT, Types.REAL,
createDecimal(ValueFloat.PRECISION, ValueFloat.PRECISION, createDecimal(ValueFloat.PRECISION, ValueFloat.PRECISION,
0, ValueFloat.DISPLAY_SIZE, false, false), 0, ValueFloat.DISPLAY_SIZE, false, false),
new String[] {"REAL", "FLOAT4"}, new String[] {"REAL", "FLOAT4"}
24
); );
add(Value.DOUBLE, Types.DOUBLE, add(Value.DOUBLE, Types.DOUBLE,
createDecimal(ValueDouble.PRECISION, ValueDouble.PRECISION, createDecimal(ValueDouble.PRECISION, ValueDouble.PRECISION,
0, ValueDouble.DISPLAY_SIZE, false, false), 0, ValueDouble.DISPLAY_SIZE, false, false),
new String[] { "DOUBLE", "DOUBLE PRECISION" }, new String[] { "DOUBLE", "DOUBLE PRECISION" }
24
); );
add(Value.DOUBLE, Types.FLOAT, add(Value.DOUBLE, Types.FLOAT,
createDecimal(ValueDouble.PRECISION, ValueDouble.PRECISION, createDecimal(ValueDouble.PRECISION, ValueDouble.PRECISION,
0, ValueDouble.DISPLAY_SIZE, false, false), 0, ValueDouble.DISPLAY_SIZE, false, false),
new String[] {"FLOAT", "FLOAT8" }, new String[] {"FLOAT", "FLOAT8" }
24
); );
add(Value.TIME, Types.TIME, add(Value.TIME, Types.TIME,
createDate(ValueTime.MAXIMUM_PRECISION, ValueTime.DEFAULT_PRECISION, createDate(ValueTime.MAXIMUM_PRECISION, ValueTime.DEFAULT_PRECISION,
"TIME", true, ValueTime.DEFAULT_SCALE, ValueTime.MAXIMUM_SCALE), "TIME", true, ValueTime.DEFAULT_SCALE, ValueTime.MAXIMUM_SCALE),
new String[]{"TIME", "TIME WITHOUT TIME ZONE"}, new String[]{"TIME", "TIME WITHOUT TIME ZONE"}
// 24 for ValueTime, 32 for java.sql.Time
56
); );
add(Value.DATE, Types.DATE, add(Value.DATE, Types.DATE,
createDate(ValueDate.PRECISION, ValueDate.PRECISION, createDate(ValueDate.PRECISION, ValueDate.PRECISION,
"DATE", false, 0, 0), "DATE", false, 0, 0),
new String[]{"DATE"}, new String[]{"DATE"}
// 24 for ValueDate, 32 for java.sql.Date
56
); );
add(Value.TIMESTAMP, Types.TIMESTAMP, add(Value.TIMESTAMP, Types.TIMESTAMP,
createDate(ValueTimestamp.MAXIMUM_PRECISION, ValueTimestamp.DEFAULT_PRECISION, createDate(ValueTimestamp.MAXIMUM_PRECISION, ValueTimestamp.DEFAULT_PRECISION,
"TIMESTAMP", true, ValueTimestamp.DEFAULT_SCALE, ValueTimestamp.MAXIMUM_SCALE), "TIMESTAMP", true, ValueTimestamp.DEFAULT_SCALE, ValueTimestamp.MAXIMUM_SCALE),
new String[]{"TIMESTAMP", "TIMESTAMP WITHOUT TIME ZONE", new String[]{"TIMESTAMP", "TIMESTAMP WITHOUT TIME ZONE",
"DATETIME", "DATETIME2", "SMALLDATETIME"}, "DATETIME", "DATETIME2", "SMALLDATETIME"}
// 24 for ValueTimestamp, 32 for java.sql.Timestamp
56
); );
// 2014 is the value of Types.TIMESTAMP_WITH_TIMEZONE // 2014 is the value of Types.TIMESTAMP_WITH_TIMEZONE
// use the value instead of the reference because the code has to // use the value instead of the reference because the code has to
...@@ -309,24 +277,19 @@ public class DataType { ...@@ -309,24 +277,19 @@ public class DataType {
createDate(ValueTimestampTimeZone.MAXIMUM_PRECISION, ValueTimestampTimeZone.DEFAULT_PRECISION, createDate(ValueTimestampTimeZone.MAXIMUM_PRECISION, ValueTimestampTimeZone.DEFAULT_PRECISION,
"TIMESTAMP_TZ", true, ValueTimestampTimeZone.DEFAULT_SCALE, "TIMESTAMP_TZ", true, ValueTimestampTimeZone.DEFAULT_SCALE,
ValueTimestampTimeZone.MAXIMUM_SCALE), ValueTimestampTimeZone.MAXIMUM_SCALE),
new String[]{"TIMESTAMP WITH TIME ZONE"}, new String[]{"TIMESTAMP WITH TIME ZONE"}
// 26 for ValueTimestampTimeZone, 32 for java.sql.Timestamp
58
); );
add(Value.BYTES, Types.VARBINARY, add(Value.BYTES, Types.VARBINARY,
createString(false), createString(false),
new String[]{"VARBINARY", "BINARY VARYING"}, new String[]{"VARBINARY", "BINARY VARYING"}
32
); );
add(Value.BYTES, Types.BINARY, add(Value.BYTES, Types.BINARY,
createString(false), createString(false),
new String[]{"BINARY", "RAW", "BYTEA", "LONG RAW"}, new String[]{"BINARY", "RAW", "BYTEA", "LONG RAW"}
32
); );
add(Value.BYTES, Types.LONGVARBINARY, add(Value.BYTES, Types.LONGVARBINARY,
createString(false), createString(false),
new String[]{"LONGVARBINARY"}, new String[]{"LONGVARBINARY"}
32
); );
dataType = new DataType(); dataType = new DataType();
dataType.prefix = dataType.suffix = "'"; dataType.prefix = dataType.suffix = "'";
...@@ -334,55 +297,45 @@ public class DataType { ...@@ -334,55 +297,45 @@ public class DataType {
add(Value.UUID, Types.BINARY, add(Value.UUID, Types.BINARY,
createString(false), createString(false),
// UNIQUEIDENTIFIER is the MSSQL mode equivalent // UNIQUEIDENTIFIER is the MSSQL mode equivalent
new String[]{"UUID", "UNIQUEIDENTIFIER"}, new String[]{"UUID", "UNIQUEIDENTIFIER"}
32
); );
add(Value.JAVA_OBJECT, Types.OTHER, add(Value.JAVA_OBJECT, Types.OTHER,
createString(false), createString(false),
new String[]{"OTHER", "OBJECT", "JAVA_OBJECT"}, new String[]{"OTHER", "OBJECT", "JAVA_OBJECT"}
24
); );
add(Value.BLOB, Types.BLOB, add(Value.BLOB, Types.BLOB,
createLob(), createLob(),
new String[]{"BLOB", "BINARY LARGE OBJECT", "TINYBLOB", "MEDIUMBLOB", new String[]{"BLOB", "BINARY LARGE OBJECT", "TINYBLOB", "MEDIUMBLOB",
"LONGBLOB", "IMAGE", "OID"}, "LONGBLOB", "IMAGE", "OID"}
// 80 for ValueLob, 24 for String
104
); );
add(Value.CLOB, Types.CLOB, add(Value.CLOB, Types.CLOB,
createLob(), createLob(),
new String[]{"CLOB", "CHARACTER LARGE OBJECT", "TINYTEXT", "TEXT", "MEDIUMTEXT", new String[]{"CLOB", "CHARACTER LARGE OBJECT", "TINYTEXT", "TEXT", "MEDIUMTEXT",
"LONGTEXT", "NTEXT", "NCLOB"}, "LONGTEXT", "NTEXT", "NCLOB"}
// 80 for ValueLob, 24 for String
104
); );
add(Value.GEOMETRY, Types.OTHER, add(Value.GEOMETRY, Types.OTHER,
createGeometry(), createGeometry(),
new String[]{"GEOMETRY"}, new String[]{"GEOMETRY"}
32
); );
dataType = new DataType(); dataType = new DataType();
dataType.prefix = "ARRAY["; dataType.prefix = "ARRAY[";
dataType.suffix = "]"; dataType.suffix = "]";
add(Value.ARRAY, Types.ARRAY, add(Value.ARRAY, Types.ARRAY,
dataType, dataType,
new String[]{"ARRAY"}, new String[]{"ARRAY"}
32
); );
dataType = new DataType(); dataType = new DataType();
dataType.maxPrecision = dataType.defaultPrecision = Integer.MAX_VALUE; dataType.maxPrecision = dataType.defaultPrecision = Integer.MAX_VALUE;
add(Value.RESULT_SET, DataType.TYPE_RESULT_SET, add(Value.RESULT_SET, DataType.TYPE_RESULT_SET,
dataType, dataType,
new String[]{"RESULT_SET"}, new String[]{"RESULT_SET"}
400
); );
dataType = createString(false); dataType = createString(false);
dataType.supportsPrecision = false; dataType.supportsPrecision = false;
dataType.supportsScale = false; dataType.supportsScale = false;
add(Value.ENUM, Types.OTHER, add(Value.ENUM, Types.OTHER,
dataType, dataType,
new String[]{"ENUM"}, new String[]{"ENUM"}
48
); );
for (int i = Value.INTERVAL_YEAR; i <= Value.INTERVAL_MINUTE_TO_SECOND; i++) { for (int i = Value.INTERVAL_YEAR; i <= Value.INTERVAL_MINUTE_TO_SECOND; i++) {
addInterval(i); addInterval(i);
...@@ -403,9 +356,7 @@ public class DataType { ...@@ -403,9 +356,7 @@ public class DataType {
ValueDecimal.DEFAULT_PRECISION, ValueDecimal.DEFAULT_PRECISION,
ValueDecimal.DEFAULT_SCALE, ValueDecimal.DEFAULT_SCALE,
ValueDecimal.DEFAULT_DISPLAY_SIZE, true, false), ValueDecimal.DEFAULT_DISPLAY_SIZE, true, false),
new String[]{"DECIMAL", "DEC"}, new String[]{"DECIMAL", "DEC"}
// 40 for ValueDecimal,
64
); );
} }
...@@ -415,8 +366,7 @@ public class DataType { ...@@ -415,8 +366,7 @@ public class DataType {
ValueDecimal.DEFAULT_PRECISION, ValueDecimal.DEFAULT_PRECISION,
ValueDecimal.DEFAULT_SCALE, ValueDecimal.DEFAULT_SCALE,
ValueDecimal.DEFAULT_DISPLAY_SIZE, true, false), ValueDecimal.DEFAULT_DISPLAY_SIZE, true, false),
new String[]{"NUMERIC", "NUMBER"}, new String[]{"NUMERIC", "NUMBER"}
64
); );
} }
...@@ -435,13 +385,12 @@ public class DataType { ...@@ -435,13 +385,12 @@ public class DataType {
dataType.maxScale = ValueInterval.MAXIMUM_SCALE; dataType.maxScale = ValueInterval.MAXIMUM_SCALE;
} }
add(type, Types.OTHER, dataType, add(type, Types.OTHER, dataType,
new String[]{("INTERVAL " + name).intern()}, new String[]{("INTERVAL " + name).intern()}
36
); );
} }
private static void add(int type, int sqlType, private static void add(int type, int sqlType,
DataType dataType, String[] names, int memory) { DataType dataType, String[] names) {
for (int i = 0; i < names.length; i++) { for (int i = 0; i < names.length; i++) {
DataType dt = new DataType(); DataType dt = new DataType();
dt.type = type; dt.type = type;
...@@ -461,7 +410,6 @@ public class DataType { ...@@ -461,7 +410,6 @@ public class DataType {
dt.defaultScale = dataType.defaultScale; dt.defaultScale = dataType.defaultScale;
dt.caseSensitive = dataType.caseSensitive; dt.caseSensitive = dataType.caseSensitive;
dt.hidden = i > 0; dt.hidden = i > 0;
dt.memory = memory;
for (DataType t2 : TYPES) { for (DataType t2 : TYPES) {
if (t2.sqlType == dt.sqlType) { if (t2.sqlType == dt.sqlType) {
dt.sqlTypePos++; dt.sqlTypePos++;
......
...@@ -314,7 +314,11 @@ public abstract class Value extends VersionedValue { ...@@ -314,7 +314,11 @@ public abstract class Value extends VersionedValue {
* @return the memory used in bytes * @return the memory used in bytes
*/ */
public int getMemory() { public int getMemory() {
return DataType.getDataType(getValueType()).memory; /*
* Java 11 with -XX:-UseCompressedOops for all values up to ValueLong
* and ValueDouble.
*/
return 24;
} }
/** /**
......
...@@ -50,6 +50,12 @@ public class ValueBoolean extends Value { ...@@ -50,6 +50,12 @@ public class ValueBoolean extends Value {
return BOOLEAN; return BOOLEAN;
} }
@Override
public int getMemory() {
// Singleton TRUE and FALSE values
return 0;
}
@Override @Override
public StringBuilder getSQL(StringBuilder builder) { public StringBuilder getSQL(StringBuilder builder) {
return builder.append(getString()); return builder.append(getString());
......
...@@ -123,7 +123,7 @@ public abstract class ValueCollectionBase extends Value { ...@@ -123,7 +123,7 @@ public abstract class ValueCollectionBase extends Value {
@Override @Override
public int getMemory() { public int getMemory() {
int memory = 32; int memory = 72;
for (Value v : values) { for (Value v : values) {
memory += v.getMemory() + Constants.MEMORY_POINTER; memory += v.getMemory() + Constants.MEMORY_POINTER;
} }
......
...@@ -103,6 +103,11 @@ public class ValueEnumBase extends Value { ...@@ -103,6 +103,11 @@ public class ValueEnumBase extends Value {
return ENUM; return ENUM;
} }
@Override
public int getMemory() {
return 120;
}
@Override @Override
public int hashCode() { public int hashCode() {
int results = 31; int results = 31;
......
...@@ -171,6 +171,12 @@ public class ValueInterval extends Value { ...@@ -171,6 +171,12 @@ public class ValueInterval extends Value {
return valueType; return valueType;
} }
@Override
public int getMemory() {
// Java 11 with -XX:-UseCompressedOops
return 48;
}
@Override @Override
public Value convertScale(boolean onlyToSmallerScale, int targetScale) { public Value convertScale(boolean onlyToSmallerScale, int targetScale) {
if (targetScale >= MAXIMUM_SCALE) { if (targetScale >= MAXIMUM_SCALE) {
......
...@@ -183,9 +183,9 @@ public class ValueJavaObject extends ValueBytes { ...@@ -183,9 +183,9 @@ public class ValueJavaObject extends ValueBytes {
@Override @Override
public int getMemory() { public int getMemory() {
if (value == null) { if (value == null) {
return DataType.getDataType(getValueType()).memory; return 40;
} }
int mem = super.getMemory(); int mem = 40;
if (javaObject != null) { if (javaObject != null) {
mem *= 2; mem *= 2;
} }
......
...@@ -515,7 +515,12 @@ public class ValueLobDb extends Value { ...@@ -515,7 +515,12 @@ public class ValueLobDb extends Value {
@Override @Override
public int getMemory() { public int getMemory() {
if (small != null) { if (small != null) {
return small.length + 104; /*
* Java 11 with -XX:-UseCompressedOops
* 0 bytes: 120 bytes
* 1 byte: 128 bytes
*/
return small.length + 127;
} }
return 140; return 140;
} }
......
...@@ -63,6 +63,12 @@ public class ValueNull extends Value { ...@@ -63,6 +63,12 @@ public class ValueNull extends Value {
return NULL; return NULL;
} }
@Override
public int getMemory() {
// Singleton value
return 0;
}
@Override @Override
public String getString() { public String getString() {
return null; return null;
......
...@@ -106,6 +106,11 @@ public class ValueResultSet extends Value { ...@@ -106,6 +106,11 @@ public class ValueResultSet extends Value {
return RESULT_SET; return RESULT_SET;
} }
@Override
public int getMemory() {
return result.getRowCount() * result.getVisibleColumnCount() * 32 + 400;
}
@Override @Override
public String getString() { public String getString() {
StringBuilder buff = new StringBuilder("("); StringBuilder buff = new StringBuilder("(");
......
...@@ -69,7 +69,12 @@ public class ValueString extends Value { ...@@ -69,7 +69,12 @@ public class ValueString extends Value {
@Override @Override
public int getMemory() { public int getMemory() {
return value.length() * 2 + 48; /*
* Java 11 with -XX:-UseCompressedOops
* Empty string: 88 bytes
* 1 to 4 UTF-16 chars: 96 bytes
*/
return value.length() * 2 + 94;
} }
@Override @Override
......
...@@ -176,6 +176,11 @@ public class ValueTimestamp extends Value { ...@@ -176,6 +176,11 @@ public class ValueTimestamp extends Value {
return TIMESTAMP; return TIMESTAMP;
} }
@Override
public int getMemory() {
return 32;
}
@Override @Override
public String getString() { public String getString() {
StringBuilder buff = new StringBuilder(MAXIMUM_PRECISION); StringBuilder buff = new StringBuilder(MAXIMUM_PRECISION);
......
...@@ -168,6 +168,12 @@ public class ValueTimestampTimeZone extends Value { ...@@ -168,6 +168,12 @@ public class ValueTimestampTimeZone extends Value {
return TIMESTAMP_TZ; return TIMESTAMP_TZ;
} }
@Override
public int getMemory() {
// Java 11 with -XX:-UseCompressedOops
return 40;
}
@Override @Override
public String getString() { public String getString() {
StringBuilder builder = new StringBuilder(ValueTimestampTimeZone.MAXIMUM_PRECISION); StringBuilder builder = new StringBuilder(ValueTimestampTimeZone.MAXIMUM_PRECISION);
......
...@@ -136,6 +136,11 @@ public class ValueUuid extends Value { ...@@ -136,6 +136,11 @@ public class ValueUuid extends Value {
return TypeInfo.TYPE_UUID; return TypeInfo.TYPE_UUID;
} }
@Override
public int getMemory() {
return 32;
}
@Override @Override
public int getValueType() { public int getValueType() {
return UUID; return UUID;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论