8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-31 12:43:02 +01:00
firebird-mirror/src/jrd/rse.h

164 lines
5.6 KiB
C
Raw Normal View History

2001-05-23 15:26:42 +02:00
/*
* PROGRAM: JRD Access Method
* MODULE: rse.h
* DESCRIPTION: Record source block definitions
*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
2002-06-29 15:03:13 +02:00
*
* 2001.07.28: Added rsb_t.rsb_skip to support LIMIT functionality.
2001-05-23 15:26:42 +02:00
*/
#ifndef JRD_RSE_H
#define JRD_RSE_H
2001-05-23 15:26:42 +02:00
// This is really funny: class rse is not defined here but in exe.h!!!
2001-12-24 03:51:06 +01:00
#include "../include/fb_blk.h"
2003-10-17 22:29:52 +02:00
#include "../common/classes/array.h"
#include "../jrd/constants.h"
2001-12-24 03:51:06 +01:00
2001-05-23 15:26:42 +02:00
#include "../jrd/dsc.h"
#include "../jrd/lls.h"
#include "../jrd/sbm.h"
2001-05-23 15:26:42 +02:00
#include "../jrd/ExtEngineManager.h"
#include "../jrd/RecordBuffer.h"
struct dsc;
namespace Jrd {
class jrd_nod;
struct sort_key_def;
class CompilerScratch;
2001-05-23 15:26:42 +02:00
// Array which stores relative pointers to impure areas of invariant nodes
typedef Firebird::SortedArray<SLONG> VarInvariantArray;
2003-10-30 14:43:37 +01:00
// Blocks used to compute optimal join order:
2008-12-05 01:56:15 +01:00
// indexed relationships block (IRL) holds
2003-10-30 14:43:37 +01:00
// information about potential join orders
2001-05-23 15:26:42 +02:00
class IndexedRelationship : public pool_alloc<type_irl>
2001-12-24 03:51:06 +01:00
{
2003-10-30 14:43:37 +01:00
public:
IndexedRelationship* irl_next; // next IRL block for stream
USHORT irl_stream; // stream reachable by relation
bool irl_unique; // is this stream reachable by unique index?
2001-12-24 03:51:06 +01:00
};
2003-10-17 22:29:52 +02:00
// Must be less then MAX_SSHORT. Not used for static arrays.
2004-04-29 13:16:31 +02:00
const int MAX_CONJUNCTS = 32000;
// Note that MAX_STREAMS currently MUST be <= MAX_UCHAR.
2003-11-04 00:59:24 +01:00
// Here we should really have a compile-time fb_assert, since this hard-coded
// limit is NOT negotiable so long as we use an array of UCHAR, where index 0
// tells how many streams are in the array (and the streams themselves are
// identified by a UCHAR).
2004-04-29 13:16:31 +02:00
const int MAX_STREAMS = 255;
2003-10-17 22:29:52 +02:00
// This is number of ULONG's needed to store bit-mapped flags for all streams
2003-10-20 12:04:44 +02:00
// OPT_STREAM_BITS = (MAX_STREAMS + 1) / sizeof(ULONG)
2003-10-17 22:29:52 +02:00
// This value cannot be increased simple way. Decrease is possible, but it is also
// hardcoded in several places such as TEST_DEP_ARRAYS macro
2004-04-29 13:16:31 +02:00
const int OPT_STREAM_BITS = 8;
2003-10-17 22:29:52 +02:00
2008-12-05 01:56:15 +01:00
// Number of streams, conjuncts, indices that will be statically allocated
2003-10-17 22:29:52 +02:00
// in various arrays. Larger numbers will have to be allocated dynamically
2004-04-29 13:16:31 +02:00
const int OPT_STATIC_ITEMS = 16;
2003-10-17 22:29:52 +02:00
2001-05-23 15:26:42 +02:00
2003-10-30 14:43:37 +01:00
// General optimizer block
class OptimizerBlk : public pool_alloc<type_opt>
2001-12-24 03:51:06 +01:00
{
2003-10-17 22:29:52 +02:00
public:
CompilerScratch* opt_csb; // compiler scratch block
2003-10-30 14:43:37 +01:00
SLONG opt_combinations; // number of partial orders considered
double opt_best_cost; // cost of best join order
USHORT opt_best_count; // longest length of indexable streams
USHORT opt_base_conjuncts; // number of conjuncts in our rse, next conjuncts are distributed parent
USHORT opt_base_parent_conjuncts; // number of conjuncts in our rse + distributed with parent, next are parent
USHORT opt_base_missing_conjuncts; // number of conjuncts in our and parent rse, but without missing
//USHORT opt_g_flags; // global flags
2003-10-17 22:29:52 +02:00
// 01 Oct 2003. Nickolay Samofatov: this static array takes as much as 256 bytes.
// This is nothing compared to original Firebird 1.5 OptimizerBlk structure size of ~180k
2008-12-05 01:56:15 +01:00
// All other arrays had been converted to dynamic to preserve memory
2003-10-17 22:29:52 +02:00
// and improve performance
2008-05-10 05:44:57 +02:00
struct opt_segment
{
2003-10-17 22:29:52 +02:00
// Index segments and their options
jrd_nod* opt_lower; // lower bound on index value
jrd_nod* opt_upper; // upper bound on index value
jrd_nod* opt_match; // conjunct which matches index segment
2003-10-17 22:29:52 +02:00
} opt_segments[MAX_INDEX_SEGMENTS];
2008-05-10 05:44:57 +02:00
struct opt_conjunct
{
2003-10-17 22:29:52 +02:00
// Conjunctions and their options
jrd_nod* opt_conjunct_node; // conjunction
2003-10-17 22:29:52 +02:00
// Stream dependencies to compute conjunct
2003-10-20 12:04:44 +02:00
ULONG opt_dependencies[(MAX_STREAMS + 1) / 32];
2003-10-17 22:29:52 +02:00
UCHAR opt_conjunct_flags;
2001-12-24 03:51:06 +01:00
};
2008-05-10 05:44:57 +02:00
struct opt_stream
{
2003-10-17 22:29:52 +02:00
// Streams and their options
IndexedRelationship* opt_relationships; // streams directly reachable by index
double opt_best_stream_cost; // best cost of retrieving first n = streams
USHORT opt_best_stream; // stream in best join order seen so far
USHORT opt_stream_number; // stream in position of join order
2003-10-17 22:29:52 +02:00
UCHAR opt_stream_flags;
};
2003-10-20 12:04:44 +02:00
Firebird::HalfStaticArray<opt_conjunct, OPT_STATIC_ITEMS> opt_conjuncts;
Firebird::HalfStaticArray<opt_stream, OPT_STATIC_ITEMS> opt_streams;
2008-01-29 11:11:52 +01:00
OptimizerBlk(MemoryPool* pool) : opt_conjuncts(*pool), opt_streams(*pool) {}
2001-12-24 03:51:06 +01:00
};
2001-05-23 15:26:42 +02:00
2003-10-30 14:43:37 +01:00
// values for opt_stream_flags
2003-10-17 22:29:52 +02:00
2003-10-30 14:43:37 +01:00
const USHORT opt_stream_used = 1; // stream is used
2001-05-23 15:26:42 +02:00
2003-10-30 14:43:37 +01:00
// values for opt_conjunct_flags
2001-05-23 15:26:42 +02:00
2003-10-30 14:43:37 +01:00
const USHORT opt_conjunct_used = 1; // conjunct is used
const USHORT opt_conjunct_matched = 2; // conjunct matches an index segment
2001-05-23 15:26:42 +02:00
2003-10-30 14:43:37 +01:00
// global optimizer bits used in opt_g_flags
2001-05-23 15:26:42 +02:00
// Obsolete: it was for PC_ENGINE
//const USHORT opt_g_stream = 1; // indicate that this is a blr_stream
2003-10-30 14:43:37 +01:00
// River block - used to hold temporary information about a group of streams
// CVC: River is a "secret" of opt.cpp, maybe a new opt.h would be adequate.
2001-05-23 15:26:42 +02:00
class River : public pool_alloc_rpt<SCHAR, type_riv>
2001-12-24 03:51:06 +01:00
{
2003-10-30 14:43:37 +01:00
public:
2009-11-28 08:38:08 +01:00
RecordSource* riv_rsb; // record source block for river
2003-10-30 14:43:37 +01:00
USHORT riv_number; // temporary number for river
UCHAR riv_count; // count of streams
UCHAR riv_streams[1]; // actual streams
2001-12-24 03:51:06 +01:00
};
2001-05-23 15:26:42 +02:00
} //namespace Jrd
2003-10-30 14:43:37 +01:00
#endif // JRD_RSE_H