8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 23:23:04 +01:00

Optimized code for domain-based variables (and procedure arguments)

This commit is contained in:
alexpeshkoff 2007-12-08 13:41:26 +00:00
parent fd03bbedd3
commit bd51630b00
6 changed files with 81 additions and 42 deletions

View File

@ -2035,7 +2035,6 @@ jrd_req* CMP_make_request(thread_db* tdbb, CompilerScratch* csb)
csb->csb_impure = REQ_SIZE + REQ_TAIL * MAX(csb->csb_n_stream, 1);
csb->csb_exec_sta.clear();
csb->csb_node = pass2(tdbb, csb, csb->csb_node, 0);
// Compile (pass2) domains DEFAULT and constraints
found = csb->csb_map_field_info.getFirst();
@ -2049,6 +2048,8 @@ jrd_req* CMP_make_request(thread_db* tdbb, CompilerScratch* csb)
found = csb->csb_map_field_info.getNext();
}
csb->csb_node = pass2(tdbb, csb, csb->csb_node, 0);
if (csb->csb_impure > MAX_REQUEST_SIZE) {
IBERROR(226); // msg 226 request size limit exceeded
}
@ -2065,7 +2066,6 @@ jrd_req* CMP_make_request(thread_db* tdbb, CompilerScratch* csb)
request->req_access = csb->csb_access;
request->req_external = csb->csb_external;
request->req_map_field_info.takeOwnership(csb->csb_map_field_info);
request->req_map_item_info.takeOwnership(csb->csb_map_item_info);
request->req_id = dbb->generateId();
// CVC: Unused.
@ -4951,6 +4951,44 @@ static jrd_nod* pass2(thread_db* tdbb, CompilerScratch* csb, jrd_nod* const node
node->nod_arg[e_src_info_node] =
pass2(tdbb, csb, node->nod_arg[e_src_info_node], node);
return node;
case nod_variable:
{
Item item(nod_variable, (IPTR) node->nod_arg[e_var_id]);
ItemInfo itemInfo;
if (csb->csb_map_item_info.get(item, itemInfo))
{
node->nod_arg[e_var_info] = reinterpret_cast<jrd_nod*>
(FB_NEW(*tdbb->getDefaultPool()) ItemInfo(*tdbb->getDefaultPool(), itemInfo));
}
}
break;
case nod_init_variable:
{
Item item(nod_variable, (IPTR) node->nod_arg[e_init_var_id]);
ItemInfo itemInfo;
if (csb->csb_map_item_info.get(item, itemInfo))
{
node->nod_arg[e_init_var_info] = reinterpret_cast<jrd_nod*>
(FB_NEW(*tdbb->getDefaultPool()) ItemInfo(*tdbb->getDefaultPool(), itemInfo));
}
}
break;
case nod_argument:
{
Item item(nod_argument,
(IPTR) node->nod_arg[e_arg_message]->nod_arg[e_msg_number],
(IPTR) node->nod_arg[e_arg_number]);
ItemInfo itemInfo;
if (csb->csb_map_item_info.get(item, itemInfo))
{
node->nod_arg[e_arg_info] = reinterpret_cast<jrd_nod*>
(FB_NEW(*tdbb->getDefaultPool()) ItemInfo(*tdbb->getDefaultPool(), itemInfo));
}
}
break;
default:
break;

View File

@ -873,10 +873,14 @@ dsc* EVL_expr(thread_db* tdbb, jrd_nod* const node)
if (!(*impure_flags & VLU_checked))
{
EVL_validate(tdbb,
Item(nod_argument, (IPTR) node->nod_arg[e_arg_message]->nod_arg[e_msg_number],
(IPTR) node->nod_arg[e_arg_number]),
&impure->vlu_desc, request->req_flags & req_null);
if (node->nod_arg[e_arg_info])
{
EVL_validate(tdbb,
Item(nod_argument, (IPTR) node->nod_arg[e_arg_message]->nod_arg[e_msg_number],
(IPTR) node->nod_arg[e_arg_number]),
reinterpret_cast<const ItemInfo*>(node->nod_arg[e_arg_info]),
&impure->vlu_desc, request->req_flags & req_null);
}
*impure_flags |= VLU_checked;
}
@ -1060,8 +1064,12 @@ dsc* EVL_expr(thread_db* tdbb, jrd_nod* const node)
if (!(impure2->vlu_flags & VLU_checked))
{
EVL_validate(tdbb, Item(nod_variable, (IPTR) node->nod_arg[e_var_id]),
&impure->vlu_desc, impure->vlu_desc.dsc_flags & DSC_null);
if (node->nod_arg[e_var_info])
{
EVL_validate(tdbb, Item(nod_variable, (IPTR) node->nod_arg[e_var_id]),
reinterpret_cast<const ItemInfo*>(node->nod_arg[e_var_info]),
&impure->vlu_desc, impure->vlu_desc.dsc_flags & DSC_null);
}
impure2->vlu_flags |= VLU_checked;
}
@ -1964,24 +1972,6 @@ void EVL_make_value(thread_db* tdbb, const dsc* desc, impure_value* value)
}
void EVL_validate(thread_db* tdbb, const Item& item, dsc* desc, bool null)
{
/**************************************
*
* E V L _ v a l i d a t e
*
**************************************
*
* Functional description
* Validate argument/variable for not null and check constraint
*
**************************************/
MapItemInfo::ValueType itemInfo;
if (tdbb->getRequest()->req_map_item_info.get(item, itemInfo))
EVL_validate(tdbb, item, &itemInfo, desc, null);
}
void EVL_validate(thread_db* tdbb, const Item& item, const ItemInfo* itemInfo, dsc* desc, bool null)
{
/**************************************

View File

@ -34,7 +34,6 @@ dsc* EVL_expr(Jrd::thread_db* tdbb, Jrd::jrd_nod* const);
bool EVL_field(Jrd::jrd_rel*, Jrd::Record*, USHORT, dsc*);
USHORT EVL_group(Jrd::thread_db* tdbb, Jrd::RecordSource*, Jrd::jrd_nod* const, USHORT);
void EVL_make_value(Jrd::thread_db* tdbb, const dsc*, Jrd::impure_value*);
void EVL_validate(Jrd::thread_db*, const Jrd::Item&, dsc*, bool);
void EVL_validate(Jrd::thread_db*, const Jrd::Item&, const Jrd::ItemInfo*, dsc*, bool);

View File

@ -323,17 +323,26 @@ void EXE_assignment(thread_db* tdbb, jrd_nod* to, dsc* from_desc, bool from_null
switch (to->nod_type)
{
case nod_variable:
EVL_validate(tdbb, Item(nod_variable, (IPTR) to->nod_arg[e_var_id]),
from_desc, null == -1);
if (to->nod_arg[e_var_info])
{
EVL_validate(tdbb,
Item(nod_variable, (IPTR) to->nod_arg[e_var_id]),
reinterpret_cast<const ItemInfo*>(to->nod_arg[e_var_info]),
from_desc, null == -1);
}
impure_flags = &((impure_value*) ((SCHAR *) request +
to->nod_arg[e_var_variable]->nod_impure))->vlu_flags;
break;
case nod_argument:
EVL_validate(tdbb,
Item(nod_argument, (IPTR) to->nod_arg[e_arg_message]->nod_arg[e_msg_number],
(IPTR) to->nod_arg[e_arg_number]),
from_desc, null == -1);
if (to->nod_arg[e_arg_info])
{
EVL_validate(tdbb,
Item(nod_argument, (IPTR) to->nod_arg[e_arg_message]->nod_arg[e_msg_number],
(IPTR) to->nod_arg[e_arg_number]),
reinterpret_cast<const ItemInfo*>(to->nod_arg[e_arg_info]),
from_desc, null == -1);
}
impure_flags = (USHORT*) ((UCHAR *) request +
(IPTR) to->nod_arg[e_arg_message]->nod_arg[e_msg_impure_flags] +
(sizeof(USHORT) * (IPTR) to->nod_arg[e_arg_number]));
@ -2687,8 +2696,9 @@ static jrd_nod* looper(thread_db* tdbb, jrd_req* request, jrd_nod* in_node)
case nod_init_variable:
if (request->req_operation == jrd_req::req_evaluate)
{
MapItemInfo::ValueType itemInfo;
if (request->req_map_item_info.get(Item(nod_variable, (IPTR) node->nod_arg[e_init_var_id]), itemInfo))
const ItemInfo* itemInfo =
reinterpret_cast<const ItemInfo*>(node->nod_arg[e_init_var_info]);
if (itemInfo)
{
jrd_nod* var_node = node->nod_arg[e_init_var_variable];
DSC* to_desc = &((impure_value*) ((SCHAR *) request + var_node->nod_impure))->vlu_desc;
@ -2696,8 +2706,8 @@ static jrd_nod* looper(thread_db* tdbb, jrd_req* request, jrd_nod* in_node)
to_desc->dsc_flags |= DSC_null;
MapFieldInfo::ValueType fieldInfo;
if (itemInfo.fullDomain &&
request->req_map_field_info.get(itemInfo.field, fieldInfo) &&
if (itemInfo->fullDomain &&
request->req_map_field_info.get(itemInfo->field, fieldInfo) &&
fieldInfo.defaultValue)
{
dsc* value = EVL_expr(tdbb, fieldInfo.defaultValue);

View File

@ -260,7 +260,8 @@ const int e_arg_flag = 0;
const int e_arg_indicator = 1;
const int e_arg_message = 2;
const int e_arg_number = 3;
const int e_arg_length = 4;
const int e_arg_info = 4;
const int e_arg_length = 5;
const int e_msg_number = 0;
const int e_msg_format = 1;
@ -402,7 +403,8 @@ const int e_xcp_length = 2;
const int e_var_id = 0;
const int e_var_variable = 1;
const int e_var_length = 2;
const int e_var_info = 2;
const int e_var_length = 3;
const int e_dcl_id = 0;
const int e_dcl_desc = 1;
@ -494,7 +496,8 @@ const int e_src_info_length = 3;
// nod_init_variable
const int e_init_var_id = 0;
const int e_init_var_variable = 1;
const int e_init_var_length = 2;
const int e_init_var_info = 2;
const int e_init_var_length = 3;
// nod_domain_validation
const int e_domval_desc = 0;

View File

@ -190,7 +190,7 @@ public:
req_blobs(pool), req_external(*pool), req_access(*pool), req_resources(*pool),
req_trg_name(*pool), req_fors(*pool), req_exec_sta(*pool),
req_invariants(*pool), req_timestamp(true), req_sql_text(*pool), req_domain_validation(NULL),
req_map_field_info(*pool), req_map_item_info(*pool)
req_map_field_info(*pool)
{}
Attachment* req_attachment; // database attachment
@ -256,7 +256,6 @@ public:
dsc* req_domain_validation; // Current VALUE for constraint validation
MapFieldInfo req_map_field_info; // Map field name to field info
MapItemInfo req_map_item_info; // Map item to item info
enum req_ta {
// order should be maintained because the numbers are stored in BLR