From: <di...@us...> - 2014-07-30 09:50:43
|
Revision: 59934 http://sourceforge.net/p/firebird/code/59934 Author: dimitr Date: 2014-07-30 09:50:33 +0000 (Wed, 30 Jul 2014) Log Message: ----------- Avoid metadata lookups while retrieving the plan (especially important in ASTs). Modified Paths: -------------- firebird/trunk/src/jrd/Optimizer.cpp firebird/trunk/src/jrd/Optimizer.h firebird/trunk/src/jrd/RecordSourceNodes.h firebird/trunk/src/jrd/btr.h firebird/trunk/src/jrd/recsrc/RecordSource.cpp Modified: firebird/trunk/src/jrd/Optimizer.cpp =================================================================== --- firebird/trunk/src/jrd/Optimizer.cpp 2014-07-30 09:29:44 UTC (rev 59933) +++ firebird/trunk/src/jrd/Optimizer.cpp 2014-07-30 09:50:33 UTC (rev 59934) @@ -1073,21 +1073,25 @@ } -InversionNode* OptimizerRetrieval::makeIndexNode(const index_desc* idx) const +InversionNode* OptimizerRetrieval::makeIndexScanNode(IndexScratch* indexScratch) const { /************************************** * - * m a k e I n d e x N o d e + * m a k e I n d e x S c a n N o d e * ************************************** * * Functional description - * Make an index node and an index retrieval block. + * Build node for index scan. * **************************************/ - // check whether this is during a compile or during - // a SET INDEX operation + if (!createIndexScanNodes) + return NULL; + + index_desc* const idx = indexScratch->idx; + + // Check whether this is during a compile or during a SET INDEX operation if (csb) CMP_post_resource(&csb->csb_resources, relation, Resource::rsc_index, idx->idx_id); else @@ -1096,40 +1100,14 @@ Resource::rsc_index, idx->idx_id); } - IndexRetrieval* retrieval = FB_NEW_RPT(pool, idx->idx_count * 2) IndexRetrieval(); - retrieval->irb_index = idx->idx_id; - memcpy(&retrieval->irb_desc, idx, sizeof(retrieval->irb_desc)); + // For external requests, determine index name (to be reported in plans) + MetaName indexName; + if (!(csb->csb_g_flags & csb_internal)) + MET_lookup_index(tdbb, indexName, relation->rel_name, idx->idx_id + 1); - InversionNode* node = FB_NEW(pool) InversionNode(retrieval); + IndexRetrieval* const retrieval = + FB_NEW(pool) IndexRetrieval(pool, relation, idx, indexName); - if (csb) - node->impure = CMP_impure(csb, sizeof(impure_inversion)); - - return node; -} - -InversionNode* OptimizerRetrieval::makeIndexScanNode(IndexScratch* indexScratch) const -{ -/************************************** - * - * m a k e I n d e x S c a n N o d e - * - ************************************** - * - * Functional description - * Build node for index scan. - * - **************************************/ - - if (!createIndexScanNodes) - return NULL; - - // Allocate both a index retrieval node and block. - index_desc* idx = indexScratch->idx; - InversionNode* node = makeIndexNode(idx); - IndexRetrieval* retrieval = node->retrieval; - retrieval->irb_relation = relation; - // Pick up lower bound segment values ValueExprNode** lower = retrieval->irb_value; ValueExprNode** upper = retrieval->irb_value + idx->idx_count; @@ -1225,7 +1203,8 @@ // mark the index as utilized for the purposes of this compile idx->idx_runtime_flags |= idx_used; - return node; + const ULONG impure = csb ? CMP_impure(csb, sizeof(impure_inversion)) : 0; + return FB_NEW(pool) InversionNode(retrieval, impure); } InversionCandidate* OptimizerRetrieval::makeInversion(InversionCandidateList* inversions) const Modified: firebird/trunk/src/jrd/Optimizer.h =================================================================== --- firebird/trunk/src/jrd/Optimizer.h 2014-07-30 09:29:44 UTC (rev 59933) +++ firebird/trunk/src/jrd/Optimizer.h 2014-07-30 09:50:33 UTC (rev 59934) @@ -187,7 +187,6 @@ InversionCandidate* generateInversion(); void getInversionCandidates(InversionCandidateList* inversions, IndexScratchList* indexScratches, USHORT scope) const; - InversionNode* makeIndexNode(const index_desc* idx) const; InversionNode* makeIndexScanNode(IndexScratch* indexScratch) const; InversionCandidate* makeInversion(InversionCandidateList* inversions) const; bool matchBoolean(IndexScratch* indexScratch, BoolExprNode* boolean, USHORT scope) const; Modified: firebird/trunk/src/jrd/RecordSourceNodes.h =================================================================== --- firebird/trunk/src/jrd/RecordSourceNodes.h 2014-07-30 09:29:44 UTC (rev 59933) +++ firebird/trunk/src/jrd/RecordSourceNodes.h 2014-07-30 09:50:33 UTC (rev 59934) @@ -188,9 +188,9 @@ { } - explicit InversionNode(IndexRetrieval* aRetrieval) + InversionNode(IndexRetrieval* aRetrieval, ULONG anImpure) : type(TYPE_INDEX), - impure(0), + impure(anImpure), retrieval(aRetrieval), node1(NULL), node2(NULL), Modified: firebird/trunk/src/jrd/btr.h =================================================================== --- firebird/trunk/src/jrd/btr.h 2014-07-30 09:29:44 UTC (rev 59933) +++ firebird/trunk/src/jrd/btr.h 2014-07-30 09:50:33 UTC (rev 59934) @@ -175,17 +175,42 @@ // Index retrieval block -- hold stuff for index retrieval -class IndexRetrieval : public pool_alloc_rpt<ValueExprNode*, type_irb> +class IndexRetrieval { public: - index_desc irb_desc; // Index descriptor - USHORT irb_index; // Index id - USHORT irb_generic; // Flags for generic search - jrd_rel* irb_relation; // Relation for retrieval - USHORT irb_lower_count; // Number of segments for retrieval - USHORT irb_upper_count; // Number of segments for retrieval - temporary_key* irb_key; // key for equality retrieval - ValueExprNode* irb_value[1]; + IndexRetrieval(jrd_rel* relation, const index_desc* idx, USHORT count, temporary_key* key) + : irb_relation(relation), irb_index(idx->idx_id), + irb_generic(0), irb_lower_count(count), irb_upper_count(count), irb_key(key), + irb_name(NULL), irb_value(NULL) + { + memcpy(&irb_desc, idx, sizeof(irb_desc)); + } + + IndexRetrieval(MemoryPool& pool, jrd_rel* relation, const index_desc* idx, + const Firebird::MetaName& name) + : irb_relation(relation), irb_index(idx->idx_id), + irb_generic(0), irb_lower_count(0), irb_upper_count(0), irb_key(NULL), + irb_name(FB_NEW(pool) Firebird::MetaName(name)), + irb_value(FB_NEW(pool) ValueExprNode*[idx->idx_count * 2]) + { + memcpy(&irb_desc, idx, sizeof(irb_desc)); + } + + ~IndexRetrieval() + { + delete irb_name; + delete[] irb_value; + } + + index_desc irb_desc; // Index descriptor + jrd_rel* irb_relation; // Relation for retrieval + USHORT irb_index; // Index id + USHORT irb_generic; // Flags for generic search + USHORT irb_lower_count; // Number of segments for retrieval + USHORT irb_upper_count; // Number of segments for retrieval + temporary_key* irb_key; // Key for equality retrieval + Firebird::MetaName* irb_name; // Index name + ValueExprNode** irb_value; }; // Flag values for irb_generic Modified: firebird/trunk/src/jrd/recsrc/RecordSource.cpp =================================================================== --- firebird/trunk/src/jrd/recsrc/RecordSource.cpp 2014-07-30 09:29:44 UTC (rev 59933) +++ firebird/trunk/src/jrd/recsrc/RecordSource.cpp 2014-07-30 09:50:33 UTC (rev 59934) @@ -122,8 +122,10 @@ const jrd_rel* const relation = retrieval->irb_relation; MetaName indexName; - MET_lookup_index(tdbb, indexName, relation->rel_name, - (USHORT) (retrieval->irb_index + 1)); + if (retrieval->irb_name && retrieval->irb_name->hasData()) + indexName = *retrieval->irb_name; + else + indexName.printf("<index id %d>", retrieval->irb_index + 1); if (detailed) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |