Skip to content

Commit

Permalink
Fixed (hopefully) CORE-2798: Incomplete plan output (lack of view nam…
Browse files Browse the repository at this point in the history
…es) when selecting from views containing procedures inside.
  • Loading branch information
dyemanov committed Dec 10, 2009
1 parent 94bf335 commit 5e787a2
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 11 deletions.
35 changes: 30 additions & 5 deletions src/jrd/cmp.cpp
Expand Up @@ -3082,11 +3082,15 @@ static jrd_nod* copy(thread_db* tdbb,
new_stream = csb->nextStream();
node->nod_arg[e_prc_stream] = (jrd_nod*) (IPTR) new_stream;
remap[stream] = (UCHAR) new_stream;
node->nod_arg[e_prc_context] = input->nod_arg[e_prc_context];
node->nod_arg[e_prc_procedure] = input->nod_arg[e_prc_procedure];
node->nod_arg[e_prc_view] = input->nod_arg[e_prc_view];
CompilerScratch::csb_repeat* element = CMP_csb_element(csb, new_stream);
// SKIDDER: Maybe we need to check if we really found a procedure?
element->csb_procedure = MET_lookup_procedure_id(tdbb,
(SSHORT)(IPTR) node->nod_arg[e_prc_procedure], false, false, 0);
element->csb_view = (jrd_rel*) node->nod_arg[e_prc_view];
element->csb_view_stream = remap[0];

csb->csb_rpt[new_stream].csb_flags |= csb->csb_rpt[stream].csb_flags & csb_no_dbkey;

Expand Down Expand Up @@ -4769,10 +4773,31 @@ static void pass1_source(thread_db* tdbb,

if (source->nod_type == nod_procedure) {
CMP_pass1(tdbb, csb, source);
jrd_prc* procedure = MET_lookup_procedure_id(tdbb,
(SSHORT)(IPTR) source->nod_arg[e_prc_procedure], false, false, 0);
jrd_prc* const procedure =
MET_lookup_procedure_id(tdbb, (SSHORT)(IPTR) source->nod_arg[e_prc_procedure], false, false, 0);
post_procedure_access(tdbb, csb, procedure);
CMP_post_resource(&csb->csb_resources, procedure, Resource::rsc_procedure, procedure->prc_id);

jrd_rel* const parent_view = csb->csb_view;
const USHORT view_stream = csb->csb_view_stream;
source->nod_arg[e_prc_view] = (jrd_nod*) parent_view;

const USHORT stream = (USHORT)(IPTR) source->nod_arg[e_prc_stream];
CompilerScratch::csb_repeat* const element = CMP_csb_element(csb, stream);
element->csb_view = parent_view;
fb_assert(view_stream <= MAX_STREAMS);
element->csb_view_stream = (UCHAR) view_stream;

if (parent_view)
{
ViewContexts& ctx = parent_view->rel_view_contexts;
const USHORT key = (USHORT)(IPTR) source->nod_arg[e_prc_context];
size_t pos;
if (ctx.find(key, pos)) {
element->csb_alias = FB_NEW(csb->csb_pool)
Firebird::string(csb->csb_pool, ctx[pos]->vcx_context_name);
}
}
return;
}

Expand Down Expand Up @@ -4803,16 +4828,16 @@ static void pass1_source(thread_db* tdbb,
source->nod_arg[e_rel_view] = (jrd_nod*) parent_view;

const USHORT stream = (USHORT)(IPTR) source->nod_arg[e_rel_stream];
CompilerScratch::csb_repeat* element = CMP_csb_element(csb, stream);
CompilerScratch::csb_repeat* const element = CMP_csb_element(csb, stream);
element->csb_view = parent_view;
fb_assert(view_stream <= MAX_STREAMS);
element->csb_view_stream = (UCHAR) view_stream;

// in the case where there is a parent view, find the context name

if (parent_view) {
ViewContexts &ctx = parent_view->rel_view_contexts;
USHORT key = (USHORT)(IPTR) source->nod_arg[e_rel_context];
ViewContexts& ctx = parent_view->rel_view_contexts;
const USHORT key = (USHORT)(IPTR) source->nod_arg[e_rel_context];
size_t pos;
if (ctx.find(key, pos)) {
element->csb_alias = FB_NEW(csb->csb_pool)
Expand Down
4 changes: 3 additions & 1 deletion src/jrd/exe.h
Expand Up @@ -406,7 +406,9 @@ const int e_prc_inputs = 0;
const int e_prc_in_msg = 1;
const int e_prc_stream = 2;
const int e_prc_procedure = 3;
const int e_prc_length = 4;
const int e_prc_view = 4;
const int e_prc_context = 5;
const int e_prc_length = 6;

// Function expression

Expand Down
19 changes: 15 additions & 4 deletions src/jrd/opt.cpp
Expand Up @@ -2456,7 +2456,7 @@ static bool dump_rsb(const jrd_req* request,
const UCHAR* name = NULL;

const VaryingString* alias = rsb->rsb_alias;
if (alias)
if (alias && rsb->rsb_type != rsb_procedure)
{
length = alias->str_length;
name = alias->str_data;
Expand Down Expand Up @@ -2558,7 +2558,15 @@ static bool dump_rsb(const jrd_req* request,

if (request->req_procedure || procedure->prc_request->req_fors.getCount() == 0)
{
const Firebird::MetaName& n = procedure->prc_name;
Firebird::MetaName n;
if (rsb->rsb_alias)
{
n.assign((char*) rsb->rsb_alias->str_data, rsb->rsb_alias->str_length);
}
else
{
n = procedure->prc_name;
}
const CHARSET_ID charset = tdbb->getAttachment()->att_charset;
if (charset != CS_METADATA && charset != CS_NONE)
{
Expand Down Expand Up @@ -4799,12 +4807,15 @@ static RecordSource* gen_procedure(thread_db* tdbb, OptimizerBlk* opt, jrd_nod*
DEV_BLKCHK(node, type_nod);
SET_TDBB(tdbb);

CompilerScratch* csb = opt->opt_csb;
CompilerScratch* const csb = opt->opt_csb;
jrd_prc* procedure = MET_lookup_procedure_id(tdbb,
(SSHORT)(IPTR)node->nod_arg[e_prc_procedure], false, false, 0);
RecordSource* rsb = FB_NEW_RPT(*tdbb->getDefaultPool(), RSB_PRC_count) RecordSource();
rsb->rsb_type = rsb_procedure;
rsb->rsb_stream = (UCHAR)(IPTR) node->nod_arg[e_prc_stream];
const UCHAR stream = (UCHAR)(IPTR) node->nod_arg[e_prc_stream];
rsb->rsb_stream = stream;
CompilerScratch::csb_repeat* const csb_tail = &csb->csb_rpt[stream];
rsb->rsb_alias = OPT_make_alias(tdbb, csb, csb_tail);
rsb->rsb_procedure = procedure;
rsb->rsb_format = procedure->prc_format;
rsb->rsb_impure = CMP_impure(csb, sizeof(struct irsb_procedure));
Expand Down
4 changes: 3 additions & 1 deletion src/jrd/par.cpp
Expand Up @@ -2036,9 +2036,11 @@ static jrd_nod* par_procedure(thread_db* tdbb, CompilerScratch* csb, SSHORT blr_
node->nod_count = count_table[blr_procedure];
node->nod_arg[e_prc_procedure] = (jrd_nod*) (IPTR) procedure->prc_id;

const USHORT stream = par_context(csb, 0);
SSHORT context;
const SSHORT stream = par_context(csb, &context);
node->nod_arg[e_prc_stream] = (jrd_nod*) (IPTR) stream;
csb->csb_rpt[stream].csb_procedure = procedure;
node->nod_arg[e_prc_context] = (jrd_nod*) (IPTR) context;

par_procedure_parms(tdbb, csb, procedure, &node->nod_arg[e_prc_in_msg],
&node->nod_arg[e_prc_inputs], true);
Expand Down

0 comments on commit 5e787a2

Please sign in to comment.