2001-05-23 15:26:42 +02:00
|
|
|
/*
|
|
|
|
* PROGRAM: JRD Access Method
|
|
|
|
* MODULE: btr.h
|
|
|
|
* DESCRIPTION: Index walking data structures
|
|
|
|
*
|
|
|
|
* 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-10-29 04:17:45 +01:00
|
|
|
*
|
|
|
|
* 2002.10.28 Sean Leyne - Code cleanup, removed obsolete "DecOSF" port
|
|
|
|
*
|
2001-05-23 15:26:42 +02:00
|
|
|
*/
|
|
|
|
|
2004-03-18 06:56:06 +01:00
|
|
|
#ifndef JRD_BTR_H
|
|
|
|
#define JRD_BTR_H
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-12-01 03:37:25 +01:00
|
|
|
#include "../jrd/constants.h"
|
2003-11-30 22:14:30 +01:00
|
|
|
#include "../common/classes/array.h"
|
2001-12-24 03:51:06 +01:00
|
|
|
#include "../include/fb_blk.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-06-21 07:46:51 +02:00
|
|
|
#include "../jrd/err_proto.h" // Index error types
|
2004-09-28 08:28:38 +02:00
|
|
|
#include "../jrd/RecordNumber.h"
|
|
|
|
#include "../jrd/sbm.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-06-21 07:46:51 +02:00
|
|
|
// 64 turns out not to be enough indexes
|
|
|
|
// #define MAX_IDX 64 // that should be plenty of indexes
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-12-01 03:37:25 +01:00
|
|
|
#define MAX_KEY_LIMIT (dbb->dbb_page_size / 4)
|
|
|
|
|
2004-03-28 11:10:30 +02:00
|
|
|
struct dsc;
|
|
|
|
|
2004-03-20 15:57:40 +01:00
|
|
|
namespace Jrd {
|
|
|
|
|
2004-03-11 06:04:26 +01:00
|
|
|
class jrd_rel;
|
2004-03-20 15:57:40 +01:00
|
|
|
class jrd_tra;
|
2005-12-02 08:35:34 +01:00
|
|
|
template <typename T> class vec;
|
2004-03-28 11:10:30 +02:00
|
|
|
class jrd_req;
|
|
|
|
struct temporary_key;
|
|
|
|
class jrd_tra;
|
2008-04-03 01:46:59 +02:00
|
|
|
class BtrPageGCLock;
|
2004-03-11 06:04:26 +01:00
|
|
|
|
2003-03-09 22:07:29 +01:00
|
|
|
enum idx_null_state {
|
|
|
|
idx_nulls_none,
|
|
|
|
idx_nulls_some,
|
|
|
|
idx_nulls_all
|
|
|
|
};
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-06-21 07:46:51 +02:00
|
|
|
// Index descriptor block -- used to hold info from index root page
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2008-05-10 05:44:57 +02:00
|
|
|
struct index_desc
|
|
|
|
{
|
2009-06-21 07:46:51 +02:00
|
|
|
SLONG idx_root; // Index root
|
|
|
|
float idx_selectivity; // selectivity of index
|
2004-03-28 11:10:30 +02:00
|
|
|
USHORT idx_id;
|
|
|
|
UCHAR idx_flags;
|
2009-06-21 07:46:51 +02:00
|
|
|
UCHAR idx_runtime_flags; // flags used at runtime, not stored on disk
|
|
|
|
USHORT idx_primary_index; // id for primary key partner index
|
|
|
|
USHORT idx_primary_relation; // id for primary key partner relation
|
|
|
|
USHORT idx_count; // number of keys
|
|
|
|
vec<int>* idx_foreign_primaries; // ids for primary/unique indexes with partners
|
|
|
|
vec<int>* idx_foreign_relations; // ids for foreign key partner relations
|
|
|
|
vec<int>* idx_foreign_indexes; // ids for foreign key partner indexes
|
|
|
|
jrd_nod* idx_expression; // node tree for indexed expresssion
|
|
|
|
dsc idx_expression_desc; // descriptor for expression result
|
|
|
|
jrd_req* idx_expression_request; // stored request for expression evaluation
|
2003-12-31 23:40:09 +01:00
|
|
|
// This structure should exactly match IRTD structure for current ODS
|
2008-05-10 05:44:57 +02:00
|
|
|
struct idx_repeat
|
|
|
|
{
|
2009-06-21 07:46:51 +02:00
|
|
|
USHORT idx_field; // field id
|
|
|
|
USHORT idx_itype; // data of field in index
|
|
|
|
float idx_selectivity; // segment selectivity
|
2003-12-31 23:40:09 +01:00
|
|
|
} idx_rpt[MAX_INDEX_SEGMENTS];
|
2004-03-28 11:10:30 +02:00
|
|
|
};
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2008-05-10 05:44:57 +02:00
|
|
|
struct IndexDescAlloc : public pool_alloc_rpt<index_desc>
|
|
|
|
{
|
2004-04-04 10:25:40 +02:00
|
|
|
index_desc items[1];
|
|
|
|
};
|
|
|
|
|
2009-06-21 08:04:18 +02:00
|
|
|
|
|
|
|
const USHORT idx_invalid = USHORT(~0); // Applies to idx_id as special value
|
|
|
|
|
2009-06-21 07:46:51 +02:00
|
|
|
// index types and flags
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-06-21 07:46:51 +02:00
|
|
|
// See jrd/intl.h for notes on idx_itype and dsc_sub_type considerations
|
|
|
|
// idx_numeric .. idx_byte_array values are compatible with VMS values
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-04-29 16:51:02 +02:00
|
|
|
const int idx_numeric = 0;
|
|
|
|
const int idx_string = 1;
|
2004-08-07 18:44:05 +02:00
|
|
|
// AB: idx_timestamp1 removed
|
2004-04-29 16:51:02 +02:00
|
|
|
const int idx_byte_array = 3;
|
|
|
|
const int idx_metadata = 4;
|
|
|
|
const int idx_sql_date = 5;
|
|
|
|
const int idx_sql_time = 6;
|
|
|
|
const int idx_timestamp2 = 7;
|
2009-06-21 07:46:51 +02:00
|
|
|
const int idx_numeric2 = 8; // Introduced for 64-bit Integer support
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-06-21 07:46:51 +02:00
|
|
|
// idx_itype space for future expansion
|
|
|
|
const int idx_first_intl_string = 64; // .. MAX (short) Range of computed key strings
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-04-29 16:51:02 +02:00
|
|
|
const int idx_offset_intl_range = (0x7FFF + idx_first_intl_string);
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-06-21 07:46:51 +02:00
|
|
|
// these flags must match the irt_flags
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-04-29 16:51:02 +02:00
|
|
|
const int idx_unique = 1;
|
|
|
|
const int idx_descending = 2;
|
|
|
|
const int idx_in_progress = 4;
|
|
|
|
const int idx_foreign = 8;
|
|
|
|
const int idx_primary = 16;
|
|
|
|
const int idx_expressn = 32;
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-06-21 07:46:51 +02:00
|
|
|
// these flags are for idx_runtime_flags
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-06-21 07:46:51 +02:00
|
|
|
const int idx_plan_dont_use = 1; // index is not mentioned in user-specified access plan
|
|
|
|
const int idx_plan_navigate = 2; // plan specifies index to be used for ordering
|
|
|
|
const int idx_used = 4; // index was in fact selected for retrieval
|
|
|
|
const int idx_navigate = 8; // index was in fact selected for navigation
|
|
|
|
const int idx_plan_missing = 16; // index mentioned in missing clause
|
|
|
|
const int idx_plan_starts = 32; // index mentioned in starts clause
|
|
|
|
const int idx_used_with_and = 64; // marker used in procedure sort_indices
|
|
|
|
const int idx_marker = 128; // marker used in procedure sort_indices
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2009-06-21 07:46:51 +02:00
|
|
|
// Index insertion block -- parameter block for index insertions
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2008-05-10 05:44:57 +02:00
|
|
|
struct index_insertion
|
|
|
|
{
|
2009-06-21 07:46:51 +02:00
|
|
|
RecordNumber iib_number; // record number (or lower level page)
|
|
|
|
SLONG iib_sibling; // right sibling page
|
|
|
|
index_desc* iib_descriptor; // index descriptor
|
|
|
|
jrd_rel* iib_relation; // relation block
|
|
|
|
temporary_key* iib_key; // varying string for insertion
|
|
|
|
RecordBitmap* iib_duplicates; // spare bit map of duplicates
|
|
|
|
jrd_tra* iib_transaction; // insertion transaction
|
2008-04-03 01:46:59 +02:00
|
|
|
BtrPageGCLock* iib_dont_gc_lock; // lock to prevent removal of splitted page
|
2004-03-28 11:10:30 +02:00
|
|
|
};
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
|
2009-06-21 07:46:51 +02:00
|
|
|
// these flags are for the key_flags
|
2004-07-16 01:01:12 +02:00
|
|
|
|
2009-06-21 07:46:51 +02:00
|
|
|
const int key_empty = 1; // Key contains empty data / empty string
|
|
|
|
const int key_all_nulls = 2; // All key fields are nulls
|
2004-07-16 01:01:12 +02:00
|
|
|
|
2009-06-21 07:46:51 +02:00
|
|
|
// Temporary key block
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2008-05-10 05:44:57 +02:00
|
|
|
struct temporary_key
|
|
|
|
{
|
2001-05-23 15:26:42 +02:00
|
|
|
USHORT key_length;
|
2005-05-28 00:45:31 +02:00
|
|
|
UCHAR key_data[MAX_KEY + 1];
|
2004-07-16 01:01:12 +02:00
|
|
|
UCHAR key_flags;
|
2008-12-05 01:56:15 +01:00
|
|
|
USHORT key_null_segment; // index of first encountered null segment.
|
|
|
|
// Evaluated in BTR_key only and used in IDX_create_index for better
|
2005-10-26 17:11:51 +02:00
|
|
|
// error diagnostics
|
|
|
|
|
2009-06-21 07:46:51 +02:00
|
|
|
// AB: I don't see the use of multiplying with 2 anymore.
|
2008-12-05 01:56:15 +01:00
|
|
|
//UCHAR key_data[MAX_KEY * 2];
|
|
|
|
// This needs to be on a SHORT boundary.
|
|
|
|
// This is because key_data is complemented as
|
2003-12-01 03:37:25 +01:00
|
|
|
// (SSHORT *) if value is negative.
|
2004-03-28 11:10:30 +02:00
|
|
|
// See compress() (JRD/btr.cpp) for more details
|
|
|
|
};
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-12-01 03:37:25 +01:00
|
|
|
|
2009-06-21 07:46:51 +02:00
|
|
|
// Index Sort Record -- fix part of sort record for index fast load
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2008-12-05 01:56:15 +01:00
|
|
|
// hvlad: index_sort_record structure is stored in sort scratch file so we
|
|
|
|
// don't want to grow sort file with padding added by compiler to please
|
|
|
|
// alignment rules.
|
2009-05-27 13:32:59 +02:00
|
|
|
#pragma pack(1)
|
2008-05-10 05:44:57 +02:00
|
|
|
struct index_sort_record
|
|
|
|
{
|
2004-10-05 23:09:51 +02:00
|
|
|
// RecordNumber should be at the first place, because it's used
|
|
|
|
// for determing sort by creating index (see idx.cpp)
|
2007-03-20 19:02:10 +01:00
|
|
|
SINT64 isr_record_number;
|
2001-05-23 15:26:42 +02:00
|
|
|
USHORT isr_key_length;
|
|
|
|
USHORT isr_flags;
|
2004-03-28 11:10:30 +02:00
|
|
|
};
|
2009-05-27 13:32:59 +02:00
|
|
|
#pragma pack()
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-04-29 16:51:02 +02:00
|
|
|
const int ISR_secondary = 1; // Record is secondary version
|
|
|
|
const int ISR_null = 2; // Record consists of NULL values only
|
2003-12-01 03:37:25 +01:00
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
|
|
|
|
|
2009-06-21 07:46:51 +02:00
|
|
|
// Index retrieval block -- hold stuff for index retrieval
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-03-19 07:14:53 +01:00
|
|
|
class IndexRetrieval : public pool_alloc_rpt<jrd_nod*, type_irb>
|
2001-12-24 03:51:06 +01:00
|
|
|
{
|
2008-05-10 05:44:57 +02:00
|
|
|
public:
|
2009-06-21 07:46:51 +02:00
|
|
|
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
|
2002-11-21 00:18:16 +01:00
|
|
|
jrd_nod* irb_value[1];
|
2001-12-24 03:51:06 +01:00
|
|
|
};
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2006-02-23 06:08:26 +01:00
|
|
|
// Flag values for irb_generic
|
2009-06-21 07:46:51 +02:00
|
|
|
const int irb_partial = 1; // Partial match: not all segments or starting of key only
|
|
|
|
const int irb_starting = 2; // Only compute "starting with" key for index segment
|
|
|
|
const int irb_equality = 4; // Probing index for equality match
|
2006-02-23 06:08:26 +01:00
|
|
|
const int irb_ignore_null_value_key = 8; // if lower bound is specified and upper bound unspecified,
|
|
|
|
// ignore looking at null value keys
|
|
|
|
const int irb_descending = 16; // Base index uses descending order
|
2005-10-27 23:52:17 +02:00
|
|
|
const int irb_exclude_lower = 32; // exclude lower bound keys while scanning index
|
|
|
|
const int irb_exclude_upper = 64; // exclude upper bound keys while scanning index
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-12-01 03:37:25 +01:00
|
|
|
// macros used to manipulate btree nodes
|
2005-08-10 15:36:42 +02:00
|
|
|
#define BTR_SIZE OFFSETA(Ods::btree_page*, btr_nodes)
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-03-28 11:10:30 +02:00
|
|
|
#define NEXT_NODE(node) (btree_nod*)(node->btn_data + node->btn_length)
|
|
|
|
#define NEXT_NODE_RECNR(node) (btree_nod*)(node->btn_data + node->btn_length + sizeof(SLONG))
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-05-03 00:36:35 +02:00
|
|
|
//#define LAST_NODE(page) (btree_nod*) ((UCHAR*) page + page->btr_length)
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2004-03-28 11:10:30 +02:00
|
|
|
//#define NEXT_EXPANDED(xxx,yyy) (btree_exp*) ((UCHAR*) xxx->btx_data + (yyy)->btn_prefix + (yyy)->btn_length)
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2003-12-14 19:22:06 +01:00
|
|
|
typedef Firebird::HalfStaticArray<float, 4> SelectivityList;
|
2003-11-30 22:14:30 +01:00
|
|
|
|
2004-03-20 15:57:40 +01:00
|
|
|
} //namespace Jrd
|
|
|
|
|
2009-06-21 07:46:51 +02:00
|
|
|
#endif // JRD_BTR_H
|
2004-03-18 06:56:06 +01:00
|
|
|
|