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/common.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
|
|
|
|
// ---------------------------------------------
|
|
|
|
|
2009-12-10 02:32:47 +01:00
|
|
|
BitmapTableScan::BitmapTableScan(CompilerScratch* csb, const string& name, UCHAR stream,
|
2010-10-12 10:02:57 +02:00
|
|
|
jrd_nod* 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;
|
|
|
|
}
|
|
|
|
|
2010-07-05 20:37:35 +02:00
|
|
|
void BitmapTableScan::dump(thread_db* tdbb, UCharBuffer& buffer) const
|
2009-12-09 19:45:44 +01:00
|
|
|
{
|
|
|
|
buffer.add(isc_info_rsb_begin);
|
|
|
|
|
|
|
|
buffer.add(isc_info_rsb_relation);
|
|
|
|
dumpName(tdbb, m_name, buffer);
|
|
|
|
|
|
|
|
buffer.add(isc_info_rsb_type);
|
|
|
|
buffer.add(isc_info_rsb_indexed);
|
|
|
|
dumpInversion(tdbb, m_inversion, buffer);
|
|
|
|
|
|
|
|
buffer.add(isc_info_rsb_end);
|
|
|
|
}
|