-
-
Notifications
You must be signed in to change notification settings - Fork 271
Expand file tree
/
Copy pathConditionalStream.cpp
More file actions
174 lines (139 loc) · 4.26 KB
/
Copy pathConditionalStream.cpp
File metadata and controls
174 lines (139 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
* The contents of this file are subject to the Initial
* Developer's 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.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
*
* Software distributed under the License is distributed AS IS,
* 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 Dmitry Yemanov
* for the Firebird Open Source RDBMS project.
*
* Copyright (c) 2011 Dmitry Yemanov <dimitr@firebirdsql.org>
* and all contributors signed below.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "firebird.h"
#include "../jrd/jrd.h"
#include "../jrd/req.h"
#include "../dsql/BoolNodes.h"
#include "../jrd/cmp_proto.h"
#include "../jrd/evl_proto.h"
#include "../jrd/mov_proto.h"
#include "../jrd/evl_proto.h"
#include "RecordSource.h"
using namespace Firebird;
using namespace Jrd;
// ------------------------------------
// Data access: predicate driven filter
// ------------------------------------
ConditionalStream::ConditionalStream(CompilerScratch* csb,
RecordSource* first, RecordSource* second,
BoolExprNode* boolean)
: RecordSource(csb),
m_first(first),
m_second(second),
m_boolean(boolean)
{
fb_assert(m_first && m_second && m_boolean);
m_impure = csb->allocImpure<Impure>();
m_cardinality = (first->getCardinality() + second->getCardinality()) / 2;
}
void ConditionalStream::internalOpen(thread_db* tdbb) const
{
Request* const request = tdbb->getRequest();
Impure* const impure = request->getImpure<Impure>(m_impure);
impure->irsb_flags = irsb_open;
impure->irsb_next = m_boolean->execute(tdbb, request) ? m_first : m_second;
impure->irsb_next->open(tdbb);
}
void ConditionalStream::close(thread_db* tdbb) const
{
Request* const request = tdbb->getRequest();
invalidateRecords(request);
Impure* const impure = request->getImpure<Impure>(m_impure);
if (impure->irsb_flags & irsb_open)
{
impure->irsb_flags &= ~irsb_open;
impure->irsb_next->close(tdbb);
}
}
bool ConditionalStream::internalGetRecord(thread_db* tdbb) const
{
JRD_reschedule(tdbb);
Request* const request = tdbb->getRequest();
Impure* const impure = request->getImpure<Impure>(m_impure);
if (!(impure->irsb_flags & irsb_open))
return false;
return impure->irsb_next->getRecord(tdbb);
}
bool ConditionalStream::refetchRecord(thread_db* tdbb) const
{
Request* const request = tdbb->getRequest();
Impure* const impure = request->getImpure<Impure>(m_impure);
if (!(impure->irsb_flags & irsb_open))
return false;
return impure->irsb_next->refetchRecord(tdbb);
}
WriteLockResult ConditionalStream::lockRecord(thread_db* tdbb, bool skipLocked) const
{
Request* const request = tdbb->getRequest();
Impure* const impure = request->getImpure<Impure>(m_impure);
if (!(impure->irsb_flags & irsb_open))
return WriteLockResult::CONFLICTED;
return impure->irsb_next->lockRecord(tdbb, skipLocked);
}
void ConditionalStream::getChildren(Array<const RecordSource*>& children) const
{
children.add(m_first);
children.add(m_second);
}
void ConditionalStream::print(thread_db* tdbb, PlanPrintContext& plan, unsigned level) const
{
if (plan.isDetailed())
{
plan += printIndent(++level) + "Condition";
printOptInfo(plan);
if (plan.goDeeper())
{
m_first->print(tdbb, plan, level);
m_second->print(tdbb, plan, level);
}
}
else
{
if (!level)
plan += "(";
m_first->print(tdbb, plan, level + 1);
plan += ", ";
m_second->print(tdbb, plan, level + 1);
if (!level)
plan += ")";
}
}
void ConditionalStream::markRecursive()
{
m_first->markRecursive();
m_second->markRecursive();
}
void ConditionalStream::findUsedStreams(StreamList& streams, bool expandAll) const
{
m_first->findUsedStreams(streams, expandAll);
m_second->findUsedStreams(streams, expandAll);
}
void ConditionalStream::invalidateRecords(Request* request) const
{
m_first->invalidateRecords(request);
m_second->invalidateRecords(request);
}
void ConditionalStream::nullRecords(thread_db* tdbb) const
{
m_first->nullRecords(tdbb);
m_second->nullRecords(tdbb);
}