~ubuntu-branches/ubuntu/karmic/firebird2.1/karmic

« back to all changes in this revision

Viewing changes to src/jrd/btr.h

  • Committer: Bazaar Package Importer
  • Author(s): Damyan Ivanov
  • Date: 2008-05-26 23:59:25 UTC
  • Revision ID: james.westby@ubuntu.com-20080526235925-2pnqj6nxpppoeaer
Tags: upstream-2.1.0.17798-0.ds2
ImportĀ upstreamĀ versionĀ 2.1.0.17798-0.ds2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      PROGRAM:        JRD Access Method
 
3
 *      MODULE:         btr.h
 
4
 *      DESCRIPTION:    Index walking data structures
 
5
 *
 
6
 * The contents of this file are subject to the Interbase Public
 
7
 * License Version 1.0 (the "License"); you may not use this file
 
8
 * except in compliance with the License. You may obtain a copy
 
9
 * of the License at http://www.Inprise.com/IPL.html
 
10
 *
 
11
 * Software distributed under the License is distributed on an
 
12
 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
 
13
 * or implied. See the License for the specific language governing
 
14
 * rights and limitations under the License.
 
15
 *
 
16
 * The Original Code was created by Inprise Corporation
 
17
 * and its predecessors. Portions created by Inprise Corporation are
 
18
 * Copyright (C) Inprise Corporation.
 
19
 *
 
20
 * All Rights Reserved.
 
21
 * Contributor(s): ______________________________________.
 
22
 *
 
23
 * 2002.10.28 Sean Leyne - Code cleanup, removed obsolete "DecOSF" port
 
24
 *
 
25
 */
 
26
 
 
27
#ifndef JRD_BTR_H
 
28
#define JRD_BTR_H
 
29
 
 
30
#include "../jrd/constants.h"
 
31
#include "../common/classes/array.h"
 
32
#include "../jrd/jrd_blks.h"
 
33
#include "../include/fb_blk.h"
 
34
 
 
35
#include "../jrd/err_proto.h"    /* Index error types */
 
36
#include "../jrd/RecordNumber.h"
 
37
#include "../jrd/sbm.h"
 
38
 
 
39
/* 64 turns out not to be enough indexes */
 
40
/* #define MAX_IDX               64     */      /* that should be plenty of indexes */
 
41
 
 
42
#define MAX_KEY_LIMIT           (dbb->dbb_page_size / 4)
 
43
 
 
44
struct dsc;
 
45
 
 
46
namespace Jrd {
 
47
 
 
48
class jrd_rel;
 
49
class jrd_tra;
 
50
template <typename T> class vec;
 
51
class jrd_req;
 
52
struct temporary_key;
 
53
class jrd_tra;
 
54
 
 
55
enum idx_null_state {
 
56
  idx_nulls_none,
 
57
  idx_nulls_some,
 
58
  idx_nulls_all
 
59
};
 
60
 
 
61
/* Index descriptor block -- used to hold info from index root page */
 
62
 
 
63
struct index_desc {
 
64
        SLONG   idx_root;                               /* Index root */
 
65
        float   idx_selectivity;                /* selectivity of index */
 
66
        USHORT  idx_id;
 
67
        UCHAR   idx_flags;
 
68
        UCHAR   idx_runtime_flags;      /* flags used at runtime, not stored on disk */
 
69
        USHORT  idx_primary_index;      /* id for primary key partner index */
 
70
        USHORT  idx_primary_relation;   /* id for primary key partner relation */
 
71
        USHORT  idx_count;                      /* number of keys */
 
72
        vec<int>*       idx_foreign_primaries;  /* ids for primary/unique indexes with partners */
 
73
        vec<int>*       idx_foreign_relations;  /* ids for foreign key partner relations */
 
74
        vec<int>*       idx_foreign_indexes;    /* ids for foreign key partner indexes */
 
75
        jrd_nod* idx_expression;        /* node tree for indexed expresssion */
 
76
        dsc             idx_expression_desc;    /* descriptor for expression result */
 
77
        jrd_req* idx_expression_request;        /* stored request for expression evaluation */
 
78
        // This structure should exactly match IRTD structure for current ODS
 
79
        struct idx_repeat {
 
80
                USHORT idx_field;               /* field id */
 
81
                USHORT idx_itype;               /* data of field in index */
 
82
                float idx_selectivity;  /* segment selectivity */
 
83
        } idx_rpt[MAX_INDEX_SEGMENTS];
 
84
};
 
85
 
 
86
struct IndexDescAlloc : public pool_alloc_rpt<index_desc> {
 
87
        index_desc items[1];
 
88
};
 
89
 
 
90
/* index types and flags */
 
91
 
 
92
/* See jrd/intl.h for notes on idx_itype and dsc_sub_type considerations */
 
93
/* idx_numeric .. idx_byte_array values are compatible with VMS values */
 
94
 
 
95
const int idx_numeric           = 0;
 
96
const int idx_string            = 1;
 
97
// AB: idx_timestamp1 removed
 
98
const int idx_byte_array        = 3;
 
99
const int idx_metadata          = 4;
 
100
const int idx_sql_date          = 5;
 
101
const int idx_sql_time          = 6;
 
102
const int idx_timestamp2        = 7;
 
103
const int idx_numeric2          = 8;    /* Introduced for 64-bit Integer support */
 
104
 
 
105
                                   /* idx_itype space for future expansion */
 
106
const int idx_first_intl_string = 64;   /* .. MAX (short) Range of computed key strings */
 
107
 
 
108
const int idx_offset_intl_range = (0x7FFF + idx_first_intl_string);
 
109
 
 
110
/* these flags must match the irt_flags */
 
111
 
 
112
const int idx_unique            = 1;
 
113
const int idx_descending        = 2;
 
114
const int idx_in_progress       = 4;
 
115
const int idx_foreign           = 8;
 
116
const int idx_primary           = 16;
 
117
const int idx_expressn          = 32;
 
118
 
 
119
/* these flags are for idx_runtime_flags */
 
120
 
 
121
const int idx_plan_dont_use     = 1;    /* index is not mentioned in user-specified access plan */
 
122
const int idx_plan_navigate     = 2;    /* plan specifies index to be used for ordering */
 
123
const int idx_used                      = 4;    /* index was in fact selected for retrieval */
 
124
const int idx_navigate          = 8;    /* index was in fact selected for navigation */
 
125
const int idx_plan_missing      = 16;   /* index mentioned in missing clause */
 
126
const int idx_plan_starts       = 32;   /* index mentioned in starts clause */
 
127
const int idx_used_with_and     = 64;   /* marker used in procedure sort_indices */
 
128
const int idx_marker            = 128;  /* marker used in procedure sort_indices */
 
129
 
 
130
/* Index insertion block -- parameter block for index insertions */
 
131
 
 
132
struct index_insertion {
 
133
        RecordNumber iib_number;                /* record number (or lower level page) */
 
134
        SLONG iib_sibling;                              /* right sibling page */
 
135
        index_desc*     iib_descriptor;         /* index descriptor */
 
136
        jrd_rel*        iib_relation;           /* relation block */
 
137
        temporary_key*  iib_key;                /* varying string for insertion */
 
138
        RecordBitmap* iib_duplicates;   /* spare bit map of duplicates */
 
139
        jrd_tra*        iib_transaction;        /* insertion transaction */
 
140
};
 
141
 
 
142
 
 
143
/* these flags are for the key_flags */
 
144
 
 
145
const int key_empty             = 1;    /* Key contains empty data / empty string */
 
146
const int key_all_nulls = 2;    /* All key fields are nulls */
 
147
 
 
148
/* Temporary key block */
 
149
 
 
150
struct temporary_key {
 
151
        USHORT key_length;
 
152
        UCHAR key_data[MAX_KEY + 1];
 
153
        UCHAR key_flags;
 
154
        USHORT key_null_segment;        // index of first encountered null segment. 
 
155
                // Evaluated in BTR_key only and used in IDX_create_index for better 
 
156
                // error diagnostics
 
157
 
 
158
 /* AB: I don't see the use of multiplying with 2 anymore. */
 
159
        //UCHAR key_data[MAX_KEY * 2];  
 
160
                // This needs to be on a SHORT boundary. 
 
161
                // This is because key_data is complemented as 
 
162
                // (SSHORT *) if value is negative.
 
163
                //  See compress() (JRD/btr.cpp) for more details
 
164
};
 
165
 
 
166
 
 
167
/* Index Sort Record -- fix part of sort record for index fast load */
 
168
 
 
169
// hvlad: index_sort_record structure is stored in sort scratch file so we 
 
170
// don't want to grow sort file with padding added by compiler to please 
 
171
// alignment rules. 
 
172
// #pragma pack is supported at least by MSVC and GCC. Don't know about
 
173
// other compilers, sorry
 
174
 
 
175
#pragma pack(push, 1)
 
176
struct index_sort_record {
 
177
        // RecordNumber should be at the first place, because it's used
 
178
        // for determing sort by creating index (see idx.cpp)
 
179
        SINT64 isr_record_number;
 
180
        USHORT isr_key_length;
 
181
        USHORT isr_flags;
 
182
};
 
183
#pragma pack(pop)
 
184
 
 
185
const int ISR_secondary = 1;    // Record is secondary version
 
186
const int ISR_null              = 2;    // Record consists of NULL values only
 
187
 
 
188
 
 
189
 
 
190
/* Index retrieval block -- hold stuff for index retrieval */
 
191
 
 
192
class IndexRetrieval : public pool_alloc_rpt<jrd_nod*, type_irb>
 
193
{
 
194
    public:
 
195
        index_desc irb_desc;                            /* Index descriptor */
 
196
        USHORT irb_index;                       /* Index id */
 
197
        USHORT irb_generic;                     /* Flags for generic search */
 
198
        jrd_rel*        irb_relation;   /* Relation for retrieval */
 
199
        USHORT irb_lower_count;         /* Number of segments for retrieval */
 
200
        USHORT irb_upper_count;         /* Number of segments for retrieval */
 
201
        temporary_key*  irb_key;                                /* key for equality retrieval */
 
202
        jrd_nod* irb_value[1];
 
203
};
 
204
 
 
205
// Flag values for irb_generic
 
206
const int irb_partial   = 1;                            /* Partial match: not all segments or starting of key only */
 
207
const int irb_starting  = 2;                            /* Only compute "starting with" key for index segment */
 
208
const int irb_equality  = 4;                            /* Probing index for equality match */
 
209
const int irb_ignore_null_value_key  = 8;       // if lower bound is specified and upper bound unspecified,
 
210
                                                                                        // ignore looking at null value keys
 
211
const int irb_descending        = 16;                   // Base index uses descending order
 
212
const int irb_exclude_lower     = 32;                   // exclude lower bound keys while scanning index
 
213
const int irb_exclude_upper     = 64;                   // exclude upper bound keys while scanning index
 
214
 
 
215
// macros used to manipulate btree nodes
 
216
#define BTR_SIZE        OFFSETA(Ods::btree_page*, btr_nodes)
 
217
 
 
218
#define NEXT_NODE(node) (btree_nod*)(node->btn_data + node->btn_length)
 
219
#define NEXT_NODE_RECNR(node)   (btree_nod*)(node->btn_data + node->btn_length + sizeof(SLONG))
 
220
 
 
221
//#define LAST_NODE(page)       (btree_nod*) ((UCHAR*) page + page->btr_length)
 
222
 
 
223
//#define NEXT_EXPANDED(xxx,yyy)        (btree_exp*) ((UCHAR*) xxx->btx_data + (yyy)->btn_prefix + (yyy)->btn_length)
 
224
 
 
225
typedef Firebird::HalfStaticArray<float, 4> SelectivityList;
 
226
 
 
227
} //namespace Jrd
 
228
 
 
229
#endif /* JRD_BTR_H */
 
230