2009-12-09 19:45:44 +01:00
|
|
|
/*
|
|
|
|
* 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): ______________________________________.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "firebird.h"
|
|
|
|
#include "../jrd/jrd.h"
|
|
|
|
#include "../jrd/req.h"
|
|
|
|
#include "../jrd/cmp_proto.h"
|
|
|
|
#include "../jrd/evl_proto.h"
|
|
|
|
#include "../jrd/vio_proto.h"
|
|
|
|
#include "../jrd/rlck_proto.h"
|
|
|
|
|
|
|
|
#include "RecordSource.h"
|
|
|
|
|
|
|
|
using namespace Firebird;
|
|
|
|
using namespace Jrd;
|
|
|
|
|
|
|
|
// ---------------------------------------------
|
|
|
|
// Data access: Bitmap (DBKEY) driven table scan
|
|
|
|
// ---------------------------------------------
|
|
|
|
|
2012-04-12 11:02:13 +02:00
|
|
|
BitmapTableScan::BitmapTableScan(CompilerScratch* csb, const string& name, StreamType stream,
|
2010-10-12 13:36:51 +02:00
|
|
|
InversionNode* inversion)
|
2009-12-09 19:45:44 +01:00
|
|
|
: RecordStream(csb, stream), m_name(csb->csb_pool, name), m_inversion(inversion)
|
|
|
|
{
|
|
|
|
fb_assert(m_inversion);
|
|
|
|
|
|
|
|
m_impure = CMP_impure(csb, sizeof(Impure));
|
|
|
|
}
|
|
|
|
|
2010-07-05 20:37:35 +02:00
|
|
|
void BitmapTableScan::open(thread_db* tdbb) const
|
2009-12-09 19:45:44 +01:00
|
|
|
{
|
2009-12-13 11:41:53 +01:00
|
|
|
//Database* const dbb = tdbb->getDatabase();
|
2009-12-09 19:45:44 +01:00
|
|
|
jrd_req* const request = tdbb->getRequest();
|
2010-04-05 23:20:08 +02:00
|
|
|
Impure* const impure = request->getImpure<Impure>(m_impure);
|
2009-12-09 19:45:44 +01:00
|
|
|
|
|
|
|
impure->irsb_flags = irsb_open;
|
|
|
|
impure->irsb_bitmap = EVL_bitmap(tdbb, m_inversion, NULL);
|
|
|
|
|
|
|
|
record_param* const rpb = &request->req_rpb[m_stream];
|
|
|
|
RLCK_reserve_relation(tdbb, request->req_transaction, rpb->rpb_relation, false);
|
|
|
|
|
|
|
|
rpb->rpb_number.setValue(BOF_NUMBER);
|
|
|
|
}
|
|
|
|
|
2010-07-05 20:37:35 +02:00
|
|
|
void BitmapTableScan::close(thread_db* tdbb) const
|
2009-12-09 19:45:44 +01:00
|
|
|
{
|
|
|
|
jrd_req* const request = tdbb->getRequest();
|
|
|
|
|
|
|
|
invalidateRecords(request);
|
|
|
|
|
2010-04-05 23:20:08 +02:00
|
|
|
Impure* const impure = request->getImpure<Impure>(m_impure);
|
2009-12-09 19:45:44 +01:00
|
|
|
|
|
|
|
if (impure->irsb_flags & irsb_open)
|
|
|
|
{
|
|
|
|
impure->irsb_flags &= ~irsb_open;
|
|
|
|
|
|
|
|
if (m_recursive && impure->irsb_bitmap)
|
|
|
|
{
|
|
|
|
delete *impure->irsb_bitmap;
|
|
|
|
*impure->irsb_bitmap = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-05 20:37:35 +02:00
|
|
|
bool BitmapTableScan::getRecord(thread_db* tdbb) const
|
2009-12-09 19:45:44 +01:00
|
|
|
{
|
|
|
|
jrd_req* const request = tdbb->getRequest();
|
|
|
|
record_param* const rpb = &request->req_rpb[m_stream];
|
2010-04-05 23:20:08 +02:00
|
|
|
Impure* const impure = request->getImpure<Impure>(m_impure);
|
2009-12-09 19:45:44 +01:00
|
|
|
|
|
|
|
if (!(impure->irsb_flags & irsb_open))
|
|
|
|
{
|
|
|
|
rpb->rpb_number.setValid(false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-12-10 02:32:47 +01:00
|
|
|
RecordBitmap** pbitmap = impure->irsb_bitmap;
|
|
|
|
RecordBitmap* bitmap;
|
|
|
|
|
2009-12-09 19:45:44 +01:00
|
|
|
if (!pbitmap || !(bitmap = *pbitmap))
|
|
|
|
{
|
|
|
|
rpb->rpb_number.setValid(false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rpb->rpb_number.isBof() ? bitmap->getFirst() : bitmap->getNext())
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
rpb->rpb_number.setValue(bitmap->current());
|
|
|
|
|
|
|
|
if (VIO_get(tdbb, rpb, request->req_transaction, request->req_pool))
|
|
|
|
{
|
|
|
|
rpb->rpb_number.setValid(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} while (bitmap->getNext());
|
|
|
|
}
|
|
|
|
|
|
|
|
rpb->rpb_number.setValid(false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-02 12:31:04 +01:00
|
|
|
void BitmapTableScan::print(thread_db* tdbb, string& plan,
|
|
|
|
bool detailed, unsigned level) const
|
2009-12-09 19:45:44 +01:00
|
|
|
{
|
2011-02-02 12:31:04 +01:00
|
|
|
if (detailed)
|
|
|
|
{
|
2011-02-10 21:22:22 +01:00
|
|
|
plan += printIndent(++level) + "Table \"" + printName(tdbb, m_name) + "\" Access By ID";
|
2011-02-02 12:31:04 +01:00
|
|
|
printInversion(tdbb, m_inversion, plan, true, level);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!level)
|
|
|
|
{
|
|
|
|
plan += "(";
|
|
|
|
}
|
2009-12-09 19:45:44 +01:00
|
|
|
|
2011-02-02 12:31:04 +01:00
|
|
|
plan += printName(tdbb, m_name) + " INDEX (";
|
|
|
|
string indices;
|
|
|
|
printInversion(tdbb, m_inversion, indices, false, level);
|
|
|
|
plan += indices + ")";
|
2009-12-09 19:45:44 +01:00
|
|
|
|
2011-02-02 12:31:04 +01:00
|
|
|
if (!level)
|
|
|
|
{
|
|
|
|
plan += ")";
|
|
|
|
}
|
|
|
|
}
|
2009-12-09 19:45:44 +01:00
|
|
|
}
|