8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 06:03:02 +01:00

Cosmetic changes with thanks to Claudio V.

A better/logical change so that the optimizer can use indices in sub-selects and aggregate-statements.
This commit is contained in:
arnobrinkman 2002-12-04 18:39:14 +00:00
parent 6178270b33
commit fb42c5b975
2 changed files with 51 additions and 25 deletions

View File

@ -40,7 +40,7 @@
*
*/
/*
$Id: cmp.cpp,v 1.28 2002-11-30 17:43:18 hippoman Exp $
$Id: cmp.cpp,v 1.29 2002-12-04 18:39:14 arnobrinkman Exp $
*/
#include "firebird.h"
@ -2184,6 +2184,8 @@ void DLL_EXPORT CMP_shutdown_database(TDBB tdbb)
IDL index;
VEC vector;
DBB dbb;
USHORT id;
JRD_REQ request;
SET_TDBB(tdbb);
dbb = tdbb->tdbb_database;
@ -2191,6 +2193,20 @@ void DLL_EXPORT CMP_shutdown_database(TDBB tdbb)
DEV_BLKCHK(dbb, type_dbb);
/* Release all database specific requests */
for (id = 0; id < irq_MAX; id++) {
if (request = (JRD_REQ) REQUEST(id)) {
CMP_release(tdbb, request);
}
}
for (id = 0; id < drq_MAX; id++) {
if (request = (JRD_REQ) DYN_REQUEST(id)) {
CMP_release(tdbb, request);
}
}
if (!(vector = dbb->dbb_relations))
return;
@ -2223,6 +2239,18 @@ void DLL_EXPORT CMP_shutdown_database(TDBB tdbb)
procedure->prc_use_count = 0;
}
}
/* if ((which == IRQ_REQUESTS && !(request = (JRD_REQ) REQUEST(id))) ||
(which == DYN_REQUESTS && !(request = (JRD_REQ) DYN_REQUEST(id))) ||
!(request->req_flags & (req_active | req_reserved))) {
if (request)
request->req_flags |= req_reserved;
THD_MUTEX_UNLOCK(dbb->dbb_mutexes + DBB_MUTX_cmp_clone);
return request;
}*/
}
@ -4733,9 +4761,7 @@ static void pass2_rse(TDBB tdbb, CSB csb, RSE rse)
node = *ptr;
if (node->nod_type == nod_relation) {
USHORT stream;
stream = (USHORT) node->nod_arg[e_rel_stream];
USHORT stream = (USHORT) node->nod_arg[e_rel_stream];
csb->csb_rpt[stream].csb_flags |= csb_active;
pass2(tdbb, csb, node, (JRD_NOD) rse);
}
@ -4743,9 +4769,12 @@ static void pass2_rse(TDBB tdbb, CSB csb, RSE rse)
pass2_rse(tdbb, csb, (RSE) node);
}
else if (node->nod_type == nod_procedure) {
USHORT stream;
stream = (USHORT) node->nod_arg[e_prc_stream];
USHORT stream = (USHORT) node->nod_arg[e_prc_stream];
csb->csb_rpt[stream].csb_flags |= csb_active;
pass2(tdbb, csb, node, (JRD_NOD) rse);
}
else if (node->nod_type == nod_aggregate) {
USHORT stream = (USHORT) node->nod_arg[e_agg_stream];
csb->csb_rpt[stream].csb_flags |= csb_active;
pass2(tdbb, csb, node, (JRD_NOD) rse);
}
@ -5119,7 +5148,6 @@ static RSB post_rse(TDBB tdbb, CSB csb, RSE rse)
**************************************/
RSB rsb;
JRD_NOD node, *ptr, *end;
USHORT stream;
SET_TDBB(tdbb);
@ -5144,11 +5172,15 @@ static RSB post_rse(TDBB tdbb, CSB csb, RSE rse)
ptr < end; ptr++) {
node = *ptr;
if (node->nod_type == nod_relation) {
stream = (USHORT) node->nod_arg[e_rel_stream];
USHORT stream = (USHORT) node->nod_arg[e_rel_stream];
csb->csb_rpt[stream].csb_flags &= ~csb_active;
}
else if (node->nod_type == nod_procedure) {
stream = (USHORT) node->nod_arg[e_prc_stream];
USHORT stream = (USHORT) node->nod_arg[e_prc_stream];
csb->csb_rpt[stream].csb_flags &= ~csb_active;
}
else if (node->nod_type == nod_aggregate) {
USHORT stream = (USHORT) node->nod_arg[e_agg_stream];
csb->csb_rpt[stream].csb_flags &= ~csb_active;
}
}

View File

@ -1507,10 +1507,6 @@ static BOOLEAN computable(CSB csb,
case nod_field:
if ((n = (USHORT) node->nod_arg[e_fld_stream]) == stream)
return FALSE;
if (!(csb->csb_rpt[n].csb_relation ||
csb->csb_rpt[n].csb_procedure ||
csb->csb_rpt[n].csb_view))
return TRUE;
if (idx_use
&& !(csb->csb_rpt[n].
csb_flags & (csb_made_river | csb_active))) return FALSE;
@ -4698,7 +4694,7 @@ static IRL indexed_relationship(TDBB tdbb, OPT opt, USHORT stream)
node = tail->opt_conjunct;
if (!(tail->opt_flags & opt_used)
&& computable(csb, node, -1, FALSE)) {
/* AB: Why only check for and-structures ?
/* AB: Why only check for AND structures ?
Added match_indices for support of "OR" with INNER JOINs */
/* match_index(tdbb, opt, stream, node, idx); */
@ -5059,19 +5055,17 @@ static JRD_NOD make_inversion(TDBB tdbb,
/* Because indices are already sort based on their selectivity
it's not needed to more then 1 index for a node */
if ((boolean->nod_type == nod_starts) && accept_starts) {
compose(&inversion,
node = make_starts(tdbb, opt, relation, boolean, stream, idx),
nod_bit_and);
node = make_starts(tdbb, opt, relation, boolean, stream, idx);
if (node) {
compose(&inversion, node, nod_bit_and);
accept_starts = FALSE;
}
}
if ((boolean->nod_type == nod_missing) && accept_missing) {
compose(&inversion,
node = make_missing(tdbb, opt, relation, boolean, stream, idx),
nod_bit_and);
node = make_missing(tdbb, opt, relation, boolean, stream, idx);
if (node) {
compose(&inversion, node, nod_bit_and);
accept_missing = FALSE;
}
}
@ -6008,7 +6002,7 @@ static void sort_indices(csb_repeat * csb_tail)
*
* Functional Description:
* Sort indices based on there selectivity.
* Lowest selectivy as first, higest as last.
* Lowest selectivy as first, highest as last.
*
***************************************************/
IDX *idx, *selected_idx;
@ -6022,15 +6016,15 @@ static void sort_indices(csb_repeat * csb_tail)
}
/* Walk through the indices and sort them into into idx_sort
where idx_sort[0] contains the lowest selectivity and
idx_sort[csb_tail->csb_indices - 1] the highest */
where idx_sort[0] contains the lowest selectivity (best) and
idx_sort[csb_tail->csb_indices - 1] the highest (worst) */
if (csb_tail->csb_idx && (csb_tail->csb_indices > 1)) {
for (j = 0; j < csb_tail->csb_indices; j++) {
selectivity = 1; /* Maximum selectivity is 1 (when all keys are the same) */
idx = csb_tail->csb_idx;
for (i = 0; i < csb_tail->csb_indices; i++) {
/* Prefer ASC indices in the case of almost same selectivities */
/* Prefer ASC indices in the case of almost the same selectivities */
if (selectivity > idx->idx_selectivity) {
same_selectivity = ((selectivity - idx->idx_selectivity) <= 0.00001);
}