Skip to content

Commit

Permalink
Improve statement memory consumption using better alignment and enum …
Browse files Browse the repository at this point in the history
…storage size.
  • Loading branch information
asfernandes committed Jun 8, 2020
1 parent 734bca7 commit b34e204
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 161 deletions.
2 changes: 1 addition & 1 deletion src/dsql/BoolNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class BinaryBoolNode : public TypedNode<BoolExprNode, ExprNode::TYPE_BINARY_BOOL
class ComparativeBoolNode : public TypedNode<BoolExprNode, ExprNode::TYPE_COMPARATIVE_BOOL>
{
public:
enum DsqlFlag
enum DsqlFlag : UCHAR
{
DFLAG_NONE,
DFLAG_ANSI_ALL,
Expand Down
39 changes: 20 additions & 19 deletions src/dsql/ExprNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,11 @@ static RegisterNode<ArithmeticNode> regArithmeticNode({blr_add, blr_subtract, bl
ArithmeticNode::ArithmeticNode(MemoryPool& pool, UCHAR aBlrOp, bool aDialect1,
ValueExprNode* aArg1, ValueExprNode* aArg2)
: TypedNode<ValueExprNode, ExprNode::TYPE_ARITHMETIC>(pool),
blrOp(aBlrOp),
dialect1(aDialect1),
label(pool),
arg1(aArg1),
arg2(aArg2)
arg2(aArg2),
blrOp(aBlrOp),
dialect1(aDialect1)
{
label = getCompatDialectVerb();
label.upper();
Expand Down Expand Up @@ -5683,8 +5683,8 @@ FieldNode::FieldNode(MemoryPool& pool, dsql_ctx* context, dsql_fld* field, Value
dsqlContext(context),
dsqlField(field),
dsqlIndices(indices),
fieldStream(0),
format(NULL),
fieldStream(0),
fieldId(0),
byId(false),
dsqlCursorField(false)
Expand All @@ -5698,8 +5698,8 @@ FieldNode::FieldNode(MemoryPool& pool, StreamType stream, USHORT id, bool aById)
dsqlContext(NULL),
dsqlField(NULL),
dsqlIndices(NULL),
fieldStream(stream),
format(NULL),
fieldStream(stream),
fieldId(id),
byId(aById),
dsqlCursorField(false)
Expand Down Expand Up @@ -6843,10 +6843,10 @@ GenIdNode::GenIdNode(MemoryPool& pool, bool aDialect1,
ValueExprNode* aArg,
bool aImplicit, bool aIdentity)
: TypedNode<ValueExprNode, ExprNode::TYPE_GEN_ID>(pool),
dialect1(aDialect1),
generator(pool, name),
arg(aArg),
step(0),
dialect1(aDialect1),
sysGen(false),
implicit(aImplicit),
identity(aIdentity)
Expand Down Expand Up @@ -8373,9 +8373,9 @@ DerivedFieldNode::DerivedFieldNode(MemoryPool& pool, const MetaName& aName, USHO
ValueExprNode* aValue)
: TypedNode<ValueExprNode, ExprNode::TYPE_DERIVED_FIELD>(pool),
name(aName),
scope(aScope),
value(aValue),
context(NULL)
context(NULL),
scope(aScope)
{
}

Expand Down Expand Up @@ -9319,13 +9319,13 @@ static RegisterNode<ParameterNode> regParameterNode({blr_parameter, blr_paramete

ParameterNode::ParameterNode(MemoryPool& pool)
: TypedNode<ValueExprNode, ExprNode::TYPE_PARAMETER>(pool),
dsqlParameterIndex(0),
dsqlParameter(NULL),
message(NULL),
argNumber(0),
argFlag(NULL),
argIndicator(NULL),
argInfo(NULL)
argInfo(NULL),
dsqlParameterIndex(0),
argNumber(0)
{
}

Expand Down Expand Up @@ -9710,10 +9710,10 @@ static RegisterNode<RecordKeyNode> regRecordKeyNode({blr_dbkey, blr_record_versi

RecordKeyNode::RecordKeyNode(MemoryPool& pool, UCHAR aBlrOp, const MetaName& aDsqlQualifier)
: TypedNode<ValueExprNode, ExprNode::TYPE_RECORD_KEY>(pool),
blrOp(aBlrOp),
dsqlQualifier(pool, aDsqlQualifier),
dsqlRelation(NULL),
recStream(0),
blrOp(aBlrOp),
aggregate(false)
{
fb_assert(blrOp == blr_dbkey || blrOp == blr_record_version || blrOp == blr_record_version2);
Expand Down Expand Up @@ -10872,12 +10872,12 @@ static RegisterNode<SubQueryNode> regSubQueryNode({
SubQueryNode::SubQueryNode(MemoryPool& pool, UCHAR aBlrOp, RecordSourceNode* aDsqlRse,
ValueExprNode* aValue1, ValueExprNode* aValue2)
: TypedNode<ValueExprNode, ExprNode::TYPE_SUBQUERY>(pool),
blrOp(aBlrOp),
ownSavepoint(true),
dsqlRse(aDsqlRse),
value1(aValue1),
value2(aValue2),
subQuery(NULL)
subQuery(NULL),
blrOp(aBlrOp),
ownSavepoint(true)
{
}

Expand Down Expand Up @@ -11958,9 +11958,9 @@ static RegisterNode<SysFuncCallNode> regSysFuncCallNode({blr_sys_function});
SysFuncCallNode::SysFuncCallNode(MemoryPool& pool, const MetaName& aName, ValueListNode* aArgs)
: TypedNode<ValueExprNode, ExprNode::TYPE_SYSFUNC_CALL>(pool),
name(pool, aName),
dsqlSpecialSyntax(false),
args(aArgs),
function(NULL)
function(NULL),
dsqlSpecialSyntax(false)
{
}

Expand Down Expand Up @@ -13304,9 +13304,9 @@ VariableNode::VariableNode(MemoryPool& pool)
: TypedNode<ValueExprNode, ExprNode::TYPE_VARIABLE>(pool),
dsqlName(pool),
dsqlVar(NULL),
varId(0),
varDecl(NULL),
varInfo(NULL)
varInfo(NULL),
varId(0)
{
}

Expand Down Expand Up @@ -13598,4 +13598,5 @@ static void setParameterInfo(dsql_par* parameter, const dsql_ctx* context)
}


static_assert(sizeof(RecordSourceNode) <= 40, "sizeof()");
} // namespace Jrd
30 changes: 15 additions & 15 deletions src/dsql/ExprNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ class ArithmeticNode : public TypedNode<ValueExprNode, ExprNode::TYPE_ARITHMETIC
void getDescDialect3(thread_db* tdbb, dsc* desc, dsc& desc1, dsc& desc2);

public:
const UCHAR blrOp;
bool dialect1;
Firebird::string label;
NestConst<ValueExprNode> arg1;
NestConst<ValueExprNode> arg2;
const UCHAR blrOp;
bool dialect1;
};


Expand Down Expand Up @@ -269,9 +269,9 @@ class CastNode : public TypedNode<ValueExprNode, ExprNode::TYPE_CAST>
public:
Firebird::MetaName dsqlAlias;
dsql_fld* dsqlField;
dsc castDesc;
NestConst<ValueExprNode> source;
NestConst<ItemInfo> itemInfo;
dsc castDesc;
bool artificial;
};

Expand Down Expand Up @@ -803,12 +803,12 @@ class FieldNode : public TypedNode<ValueExprNode, ExprNode::TYPE_FIELD>
dsql_ctx* const dsqlContext;
dsql_fld* const dsqlField;
NestConst<ValueListNode> dsqlIndices;
const StreamType fieldStream;
const Format* format;
const StreamType fieldStream;
Nullable<USHORT> cursorNumber;
const USHORT fieldId;
const bool byId;
bool dsqlCursorField;
Nullable<USHORT> cursorNumber;
};


Expand Down Expand Up @@ -845,10 +845,10 @@ class GenIdNode : public TypedNode<ValueExprNode, ExprNode::TYPE_GEN_ID>
virtual dsc* execute(thread_db* tdbb, jrd_req* request) const;

public:
const bool dialect1;
GeneratorItem generator;
NestConst<ValueExprNode> arg;
SLONG step;
const bool dialect1;

private:
bool sysGen;
Expand Down Expand Up @@ -1077,9 +1077,9 @@ class DerivedFieldNode : public TypedNode<ValueExprNode, ExprNode::TYPE_DERIVED_

public:
Firebird::MetaName name;
USHORT scope;
NestConst<ValueExprNode> value;
dsql_ctx* context;
USHORT scope;
};


Expand Down Expand Up @@ -1198,7 +1198,7 @@ class NullNode : public TypedNode<ValueExprNode, ExprNode::TYPE_NULL>
class OrderNode : public DsqlNode<OrderNode, ExprNode::TYPE_ORDER>
{
public:
enum NullsPlacement
enum NullsPlacement : UCHAR
{
NULLS_DEFAULT,
NULLS_FIRST,
Expand Down Expand Up @@ -1545,13 +1545,13 @@ class ParameterNode : public TypedNode<ValueExprNode, ExprNode::TYPE_PARAMETER>
virtual dsc* execute(thread_db* tdbb, jrd_req* request) const;

public:
USHORT dsqlParameterIndex;
dsql_par* dsqlParameter;
NestConst<MessageNode> message;
USHORT argNumber;
NestConst<ValueExprNode> argFlag;
NestConst<ValueExprNode> argIndicator;
NestConst<ItemInfo> argInfo;
USHORT dsqlParameterIndex;
USHORT argNumber;
};


Expand Down Expand Up @@ -1625,10 +1625,10 @@ class RecordKeyNode : public TypedNode<ValueExprNode, ExprNode::TYPE_RECORD_KEY>
void raiseError(dsql_ctx* context) const;

public:
const UCHAR blrOp;
Firebird::MetaName dsqlQualifier;
NestConst<RecordSourceNode> dsqlRelation;
StreamType recStream;
const UCHAR blrOp;
bool aggregate;
};

Expand Down Expand Up @@ -1867,13 +1867,13 @@ class SubQueryNode : public TypedNode<ValueExprNode, ExprNode::TYPE_SUBQUERY>
virtual dsc* execute(thread_db* tdbb, jrd_req* request) const;

public:
const UCHAR blrOp;
bool ownSavepoint;
NestConst<RecordSourceNode> dsqlRse;
NestConst<RseNode> rse;
NestConst<ValueExprNode> value1;
NestConst<ValueExprNode> value2;
NestConst<SubQuery> subQuery;
const UCHAR blrOp;
bool ownSavepoint;
};


Expand Down Expand Up @@ -1984,9 +1984,9 @@ class SysFuncCallNode : public TypedNode<ValueExprNode, ExprNode::TYPE_SYSFUNC_C

public:
Firebird::MetaName name;
bool dsqlSpecialSyntax;
NestConst<ValueListNode> args;
const SysFunction* function;
bool dsqlSpecialSyntax;
};


Expand Down Expand Up @@ -2144,9 +2144,9 @@ class VariableNode : public TypedNode<ValueExprNode, ExprNode::TYPE_VARIABLE>
public:
Firebird::MetaName dsqlName;
NestConst<dsql_var> dsqlVar;
USHORT varId;
NestConst<DeclareVariableNode> varDecl;
NestConst<ItemInfo> varInfo;
USHORT varId;
};


Expand Down
42 changes: 22 additions & 20 deletions src/dsql/Nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1066,20 +1066,20 @@ class WinFuncNode : public AggNode
class RecordSourceNode : public ExprNode
{
public:
static const unsigned DFLAG_SINGLETON = 0x01;
static const unsigned DFLAG_VALUE = 0x02;
static const unsigned DFLAG_RECURSIVE = 0x04; // recursive member of recursive CTE
static const unsigned DFLAG_DERIVED = 0x08;
static const unsigned DFLAG_DT_IGNORE_COLUMN_CHECK = 0x10;
static const unsigned DFLAG_DT_CTE_USED = 0x20;
static const unsigned DFLAG_CURSOR = 0x40;
static const unsigned DFLAG_LATERAL = 0x80;
static const USHORT DFLAG_SINGLETON = 0x01;
static const USHORT DFLAG_VALUE = 0x02;
static const USHORT DFLAG_RECURSIVE = 0x04; // recursive member of recursive CTE
static const USHORT DFLAG_DERIVED = 0x08;
static const USHORT DFLAG_DT_IGNORE_COLUMN_CHECK = 0x10;
static const USHORT DFLAG_DT_CTE_USED = 0x20;
static const USHORT DFLAG_CURSOR = 0x40;
static const USHORT DFLAG_LATERAL = 0x80;

RecordSourceNode(Type aType, MemoryPool& pool)
: ExprNode(aType, pool),
dsqlFlags(0),
dsqlContext(NULL),
stream(INVALID_STREAM)
stream(INVALID_STREAM),
dsqlFlags(0)
{
}

Expand Down Expand Up @@ -1158,11 +1158,13 @@ class RecordSourceNode : public ExprNode
virtual RecordSource* compile(thread_db* tdbb, OptimizerBlk* opt, bool innerSubStream) = 0;

public:
unsigned dsqlFlags;
dsql_ctx* dsqlContext;

protected:
StreamType stream;

public:
USHORT dsqlFlags;
};


Expand Down Expand Up @@ -1389,7 +1391,7 @@ class StmtNode : public DmlNode
TYPE_EXT_TRIGGER
};

enum WhichTrigger
enum WhichTrigger : UCHAR
{
ALL_TRIGS = 0,
PRE_TRIG = 1,
Expand All @@ -1409,13 +1411,13 @@ class StmtNode : public DmlNode
oldPool(tdbb->getDefaultPool()),
oldRequest(tdbb->getRequest()),
oldTransaction(tdbb->getTransaction()),
errorPending(false),
catchDisabled(false),
topNode(NULL),
prevNode(NULL),
whichEraseTrig(ALL_TRIGS),
whichStoTrig(ALL_TRIGS),
whichModTrig(ALL_TRIGS),
topNode(NULL),
prevNode(NULL),
errorPending(false),
catchDisabled(false),
exit(false)
{
savedTdbb->setTransaction(transaction);
Expand All @@ -1432,13 +1434,13 @@ class StmtNode : public DmlNode
MemoryPool* oldPool; // Save the old pool to restore on exit.
jrd_req* oldRequest; // Save the old request to restore on exit.
jrd_tra* oldTransaction; // Save the old transcation to restore on exit.
bool errorPending; // Is there an error pending to be handled?
bool catchDisabled; // Catch errors so we can unwind cleanly.
const StmtNode* topNode;
const StmtNode* prevNode;
WhichTrigger whichEraseTrig;
WhichTrigger whichStoTrig;
WhichTrigger whichModTrig;
const StmtNode* topNode;
const StmtNode* prevNode;
bool errorPending; // Is there an error pending to be handled?
bool catchDisabled; // Catch errors so we can unwind cleanly.
bool exit; // Exit the looper when true.
};

Expand Down
Loading

0 comments on commit b34e204

Please sign in to comment.