This repository was archived by the owner on Jun 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathExCompoundStmt.cpp
More file actions
651 lines (562 loc) · 23.9 KB
/
ExCompoundStmt.cpp
File metadata and controls
651 lines (562 loc) · 23.9 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
/**********************************************************************
// @@@ START COPYRIGHT @@@
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
// @@@ END COPYRIGHT @@@
**********************************************************************/
/* -*-C++-*-
******************************************************************************
*
* File: ExCompoundStmt.cpp
* Description: 3GL compound statement (CS) operator.
*
* Created: 4/1/98
* Language: C++
*
*
*
******************************************************************************
*/
#include "ex_stdh.h"
#include "ComTdb.h"
#include "ex_tcb.h"
#include "ex_expr.h"
#include "ex_error.h"
#include "str.h"
#include "ExCompoundStmt.h"
#include "ExStats.h"
//////////////////////////////////////////////////////////////////////////////
// CatpoundStmt TDB methods.
//////////////////////////////////////////////////////////////////////////////
ex_tcb * ExCatpoundStmtTdb::build(ex_globals *glob)
{
ex_tcb *left = tdbLeft_->build(glob);
ex_tcb *right = tdbRight_->build(glob);
ExCatpoundStmtTcb *cs =
new(glob->getSpace()) ExCatpoundStmtTcb(*this, *left, *right, glob);
cs->registerSubtasks();
return cs;
} // ExCatpoundStmtTdb::build
//////////////////////////////////////////////////////////////////////////////
// CatpoundStmt TCB methods.
//////////////////////////////////////////////////////////////////////////////
ExCatpoundStmtTcb::ExCatpoundStmtTcb(const ExCatpoundStmtTdb &tdb,
const ex_tcb &left,
const ex_tcb &right,
ex_globals *glob) :
ex_tcb(tdb, 1, glob)
{
CollHeap *space = glob->getSpace();
// Init children TCB handles.
tcbLeft_ = &left;
tcbRight_ = &right;
// Init queue pairs used to communicate with children.
qleft_ = left.getParentQueue();
qright_ = right.getParentQueue();
// flowParent2Right's rentry->copyAtp(lentry) requires right down-queue
// allocate its ATPs. Otherwise, rentry->copyAtp() will crash because
// of a null qright_.down->queue.atp_.
qright_.down->allocateAtps(glob->getSpace());
ex_cri_desc *criDown = tdb.criDescDown_;
ex_cri_desc *criUp = tdb.criDescUp_;
// Allocate queue pair used to communicate with parent.
qparent_.down = new(space) ex_queue(ex_queue::DOWN_QUEUE,
tdb.queueSizeDown_,
criDown,
space);
qparent_.up = new(space) ex_queue(ex_queue::UP_QUEUE,
tdb.queueSizeUp_,
criUp,
space);
// Allocate private state in each entry of the down queue.
ExCatpoundStmtPrivateState *p = new(space) ExCatpoundStmtPrivateState(this);
qparent_.down->allocatePstate(p, this);
delete p;
// remember parent's down-queue index
parent2leftx_ = qparent_.down->getHeadIndex();
// remember left child's up-queue index
leftupx_ = qleft_.up->getHeadIndex();
} // ExCatpoundStmtTcb::ExCatpoundStmtTcb
ExCatpoundStmtTcb::~ExCatpoundStmtTcb()
{
delete qparent_.up;
delete qparent_.down;
freeResources();
} // ExCatpoundStmtTcb::~ExCatpoundStmtTcb
void ExCatpoundStmtTcb::registerSubtasks()
{
ExScheduler *sched = getGlobals()->getScheduler();
// schedule sWorkDownLeft only if parent down-queue is non-empty
// or if left child down-queue is non-full.
sched->registerInsertSubtask(sWorkDownLeft, this, qparent_.down,"P1");
sched->registerUnblockSubtask(sWorkDownLeft, this, qleft_.down);
// schedule sWorkLeft2Right only if left child up-queue is non-empty
// or if right child down-queue or parent up-queue is non-full
sched->registerInsertSubtask(sWorkLeft2Right, this, qleft_.up,"P2");
sched->registerUnblockSubtask(sWorkLeft2Right, this, qright_.down);
sched->registerUnblockSubtask(sWorkLeft2Right, this, qparent_.up);
// schedule sWorkUp only if right child up-queue is non-empty
// or if parent up-queue is non-full.
sched->registerInsertSubtask(sWorkUp, this, qright_.up,"P3");
sched->registerUnblockSubtask(sWorkUp, this, qparent_.up);
// schedule sWorkCancel if a cancel request is received
sched->registerCancelSubtask(sWorkCancel, this, qparent_.down,"CN");
} // ExCatpoundStmtTcb::registerSubtasks
inline const ex_tcb* ExCatpoundStmtTcb::getChild(Int32 pos) const
{
ex_assert((pos >= 0), "ExCatpoundStmtTcb::getChild");
if (pos == 0)
return tcbLeft_;
else if (pos == 1)
return tcbRight_;
else
return NULL;
} // ExCatpoundStmtTcb::getChild
ExWorkProcRetcode ExCatpoundStmtTcb::work()
{
// The work methods for the CS operator:
// (1) workDownLeft() - Process new request, giving it to the left child.
// (2) workLeft2Right() - Flow tuple value and control from left to right.
// (3) workUp() - Flow result from right up-queue to parent up-queue.
// This default work method is never called.
ex_assert(0, "ExCatpoundStmtTcb::work: Invalid state");
return WORK_OK;
} // ExCatpoundStmtTcb::work
// Work procedure to send requests down to left child
ExWorkProcRetcode ExCatpoundStmtTcb::workDownLeft()
{
// while we have unprocessed down requests and while left
// child's down queue has room, start more child requests
while (qparent_.down->entryExists(parent2leftx_) &&
!qleft_.down->isFull()) {
startLeftChild();
parent2leftx_++;
}
return WORK_OK;
} // ExCatpoundStmtTcb::workDownLeft
void ExCatpoundStmtTcb::startLeftChild()
{
// Process the new parent request.
ex_queue_entry *pentry = qparent_.down->getQueueEntry(parent2leftx_);
ex_queue_entry *lentry = qleft_.down->getTailEntry();
ExCatpoundStmtPrivateState &pstate =
*((ExCatpoundStmtPrivateState*)pentry->pstate);
// Init private state.
pstate.init();
// pass same request to left child
const ex_queue::down_request request = pentry->downState.request;
lentry->downState.request = request;
lentry->downState.requestValue = pentry->downState.requestValue;
lentry->downState.parentIndex = parent2leftx_;
lentry->passAtp(pentry);
qleft_.down->insert();
pstate.leftstate_ = CS_STARTED;
if (request == ex_queue::GET_NOMORE) {
// immediately cancel the request (requests are already in
// cancelled state but the cancel callback isn't activated yet)
qleft_.down->cancelRequestWithParentIndex(parent2leftx_);
pstate.leftstate_ = CS_CANCELLED;
}
} // ExCatpoundStmtTcb::startLeftChild
// flow tuple values and control from left to right child
ExWorkProcRetcode ExCatpoundStmtTcb::workLeft2Right()
{
// We want to remove left up-queue entries as soon as they're passed to
// the right child. But, we can't. We must defer removing some (ie, the
// 1st and its Q_NO_DATA) left up-queue entries to workUp because
// catpoundstmts like
// begin; select count(*) from t; delete from t; end;
// may have a right child that produce no data result, ie, its first
// up-queue entry is a Q_NO_DATA. Q_NO_DATA does not carry any data.
// We must flow any left data up to the parent even if the right child
// is a non-data-producing statement.
// while left child's up-queue is non-empty do
for (; qleft_.up->entryExists(leftupx_); leftupx_++) {
// process reply from left child
ex_queue_entry *lentry = qleft_.up->getQueueEntry(leftupx_);
ex_queue_entry *rentry = qright_.down->getTailEntry();
ex_queue_entry *pentry = qparent_.down->getQueueEntry
(lentry->upState.parentIndex);
ExCatpoundStmtPrivateState &pstate =
*((ExCatpoundStmtPrivateState*)pentry->pstate);
switch(lentry->upState.status) {
case ex_queue::Q_NO_DATA:
// if we did not get atleast one row from the left child and we
// are expecting rows (because of SELECT) from the left child
// then raise a warning and stop further execution of CS statements
if (pstate.leftstate_ == CS_STARTED &&
expectingLeftRows() ) {
if (qparent_.up->isFull()) return WORK_OK; // try again later
pstate.leftstate_ = CS_ERROR;
if (afterUpdate()) {
processEODErrorOrWarning(FALSE);
}
else {
processEODErrorOrWarning(TRUE);
}
if (qparent_.up->isFull()) return WORK_OK;
}
if (pstate.leftstate_ == CS_ERROR ||
pstate.leftstate_ == CS_CANCELLED) {
if (qparent_.up->isFull())return WORK_OK; // try again later
passChildReplyUp(lentry); // pass EOD up
if (pstate.leftrows_ > 0) {
// some data is parked in up-queue; flush it.
qleft_.up->removeHead(); // the 1st row
}
// we must remove left up-queue's EOD.
qleft_.up->removeHead(); // the EOD
qparent_.down->removeHead(); // done with this request
}
else { // it's not an error nor a cancel
if (qright_.down->isFull()) return WORK_OK; // try again later
// for safety and correctness, we wait until
// left is done before passing control to right
if (pstate.leftstate_ == CS_STARTED) { // left has no data result
// flow parent's down-queue entry to the right
flowParent2Right(lentry->upState.parentIndex);
qleft_.up->removeHead(); // it's now useless
}
qright_.down->insert();
pstate.leftstate_ = CS_DONE;
pstate.rightstate_ = CS_STARTED;
if (pentry->downState.request == ex_queue::GET_NOMORE) {
// immediately cancel the request
qright_.down->cancelRequestWithParentIndex
(lentry->upState.parentIndex);
pstate.rightstate_ = CS_CANCELLED;
}
}
break;
case ex_queue::Q_OK_MMORE:
if (pstate.leftstate_ == CS_ERROR ||
pstate.leftstate_ == CS_CANCELLED) {
qleft_.up->removeHead(); // toss it out; it's useless
continue;
}
if (pstate.leftrows_ == 0) {
// make sure right child's down-queue is not full before
// changing its tail entry.
if (qright_.down->isFull()) return WORK_OK; // try again later
// catpound statement flows only 1st row from left to right
flowLeft2Right(lentry);
pstate.leftstate_ = CS_NOT_EMPTY;
}
else { // pstate.leftrows_ > 0
pentry->downState.request = ex_queue::GET_NOMORE;
if (qparent_.up->isFull()) return WORK_OK; // try again later
pstate.leftstate_ = CS_ERROR;
processCardinalityError(lentry);
qleft_.up->removeHead(); // toss it out; it's useless
}
pstate.leftrows_++;
break;
case ex_queue::Q_SQLERROR:
if (pstate.leftstate_ == CS_ERROR ||
pstate.leftstate_ == CS_CANCELLED) {
qleft_.up->removeHead(); // toss it out; it's useless
continue;
}
pentry->downState.request = ex_queue::GET_NOMORE;
if (qparent_.up->isFull()) return WORK_OK; // try again later
pstate.leftstate_ = CS_ERROR;
processError(lentry->getAtp(), NULL);
qleft_.up->removeHead(); // toss it out; it's useless
// pstate.leftrows_++; don't do this here because the Q_NO_DATA
// case above checks for a positive leftrows_ and will try to
// remove the entry we've just removed from the left up-queue.
break;
case ex_queue::Q_INVALID:
default:
ex_assert(0,"ExCatpoundStmtTcb:workLeft2Right: Invalid state");
break;
}
}
return WORK_OK;
} // ExCatpoundStmtTcb::workLeft2Right
// flow tuple value from left to right
void ExCatpoundStmtTcb::flowLeft2Right(ex_queue_entry *lentry)
{
ex_queue_entry *rentry = qright_.down->getTailEntry();
ex_queue_entry *pentry = qparent_.down->getQueueEntry
(lentry->upState.parentIndex);
// pass same request from left to right child
rentry->downState.request = pentry->downState.request;
rentry->downState.requestValue = pentry->downState.requestValue;
// associate right-down request with left-up entry's parent index
rentry->downState.parentIndex = lentry->upState.parentIndex;
// catpound statement flows any input data from left to right
rentry->copyAtp(lentry);
// passAtp may be OK here. But, we use copyAtp to be consistent with
// ExCatpoundStmtTcb::flowParent2Right
} // ExCatpoundStmtTcb::flowLeft2Right
// flow tuple value from parent to right
void ExCatpoundStmtTcb::flowParent2Right(queue_index pindex)
{
// We're the 2nd catpoundstmt node in a 3-statement block like this
// begin; select a from t; delete from u; select b from v; end;
// The queues look like this
// +--+
// |CS|
// +--+
// | | +-+ | | +-+
// | | | | |g| | |
// +-+ | | +-+ | |
// +--+ +--+
// |S | |CS|
// +--+ +--+
// | | +-+ | | +-+
// | | |e| | | | |
// +-+ | | +-+ | |
// +--+ +--+
// |D | |S |
// +--+ +--+
// The 1st catpoundstmt flowed the 1st select's result to our parent's
// down-queue(g). Our left child (the delete) has a Q_NO_DATA in its up-
// queue(e). Now, we must flow our parent's down-queue data (g) to our
// right child's down-queue. If we don't do this (and instead flow our
// left up-queue to the right down-queue), we'll lose the 1st select's
// result because our left up-queue has nothing but a Q_NO_DATA.
ex_queue_entry *rentry = qright_.down->getTailEntry();
ex_queue_entry *pentry = qparent_.down->getQueueEntry(pindex);
// pass same request from parent to right child
rentry->downState.request = pentry->downState.request;
rentry->downState.requestValue = pentry->downState.requestValue;
// associate right-down request with parent index
rentry->downState.parentIndex = pindex;
// pass data from parent-to-right
rentry->copyAtp(pentry);
// passAtp would be incorrect here because catpoundstmts like this
// begin; set :h = select c from t; insert into s(d) values(:h); end;
// require that :h be set to null if "select c from t" has no data.
// In this case, copyAtp sets :h to null whereas passAtp leaves :h
// uninitialized.
} // ExCatpoundStmtTcb::flowParent2Right
ExWorkProcRetcode ExCatpoundStmtTcb::workUp()
{
// while there is work that has been started do
while (qparent_.down->getHeadIndex() != parent2leftx_) {
// get head entry and pstate
ex_queue_entry *pdentry = qparent_.down->getHeadEntry();
ExCatpoundStmtPrivateState &pstate =
*((ExCatpoundStmtPrivateState*) pdentry->pstate);
Int32 eod = 0;
// while we have (up or cancel or error) work to do, ie,
// while right child's up-queue is non-empty do
for (; !qright_.up->isEmpty() && !eod; qright_.up->removeHead()) {
// get right child's first up-queue entry
ex_queue_entry *rentry = qright_.up->getHeadEntry();
// get parent's last up-queue entry
ex_queue_entry *puentry = qparent_.up->getTailEntry();
switch (rentry->upState.status) {
case ex_queue::Q_NO_DATA:
// any room in the up-queue?
if (qparent_.up->isFull()) return WORK_OK; // no, try again later
// if we did not get atleast one row from the right child and we
// are expecting rows (because of SELECT) from the right child
// then raise a warning and stop further execution of CS statements
if (pstate.rightstate_ == CS_STARTED &&
expectingRightRows() ) {
pstate.rightstate_ = CS_ERROR;
if (afterUpdate()) {
processEODErrorOrWarning(FALSE);
}
else {
processEODErrorOrWarning(TRUE);
}
if (qparent_.up->isFull()) return WORK_OK;
}
if (pstate.rightstate_ == CS_ERROR ||
pstate.rightstate_ == CS_CANCELLED) {
passChildReplyUp(rentry); // pass EOD up
}
else {
if (pstate.rightstate_ == CS_STARTED && pstate.leftrows_ > 0) {
// right has no data but left has some. pass left data up.
passChildReplyUp(qleft_.up->getHeadEntry());
pstate.rightrows_ = pstate.leftrows_;
if (qparent_.up->isFull()) {
pstate.rightstate_ = CS_DONE; // pass it up exactly once
return WORK_OK; // retry passing EOD later
}
}
pstate.rightstate_ = CS_DONE;
passChildReplyUp(rentry); // pass EOD up
if (getStatsEntry() != NULL) {
getStatsEntry()->setActualRowsReturned(pstate.rightrows_);
}
}
eod = 1; // this parent request is done
if (pstate.leftrows_ > 0) {
// left had some data and that data has been catenated into right
// child's atp, flush that left child data parked in it's up-queue.
qleft_.up->removeHead(); // left data
qleft_.up->removeHead(); // left EOD
}
break;
case ex_queue::Q_OK_MMORE:
case ex_queue::Q_SQLERROR:
// if right is cancelled or an error, then throw it away
if (pstate.rightstate_ == CS_ERROR ||
pstate.rightstate_ == CS_CANCELLED) continue;
if (qparent_.up->isFull()) return WORK_OK; // retry later
if (rentry->upState.status == ex_queue::Q_SQLERROR) {
pstate.rightstate_ = CS_ERROR;
processError(rentry->getAtp(), NULL);
}
// catpound statement passes-up only 1st row from right
else if (pstate.rightrows_ == 0) {
passChildReplyUp(rentry);
pstate.rightstate_ = CS_NOT_EMPTY;
}
else if (pstate.rightrows_ > 0) {
pstate.rightstate_ = CS_ERROR;
processCardinalityError(rentry);
}
pstate.rightrows_++;
break;
case ex_queue::Q_INVALID:
default:
ex_assert(0,"ExCatpoundStmtTcb::workUp: Invalid state");
break;
}
}
// right child's up-queue is empty or current request is done
if (eod)
qparent_.down->removeHead(); // this parent request is done
else
return WORK_OK;
}
return WORK_OK;
} // ExCatpoundStmtTcb::workUp
void ExCatpoundStmtTcb::passChildReplyUp(ex_queue_entry *centry)
{
// get parent's down-queue head entry and its pstate
ex_queue_entry *pdentry = qparent_.down->getHeadEntry();
// get parent's last up-queue entry
ex_queue_entry *puentry = qparent_.up->getTailEntry();
// prepare to pass rentry up to parent's up-queue
puentry->upState.status = centry->upState.status;
puentry->upState.setMatchNo(centry->upState.getMatchNo());
puentry->upState.parentIndex = pdentry->downState.parentIndex;
puentry->upState.downIndex = qparent_.down->getHeadIndex();
// pass the reply up to the parent's up-queue
puentry->copyAtp(centry);
qparent_.up->insert();
} // ExCatpoundStmtTcb::passChildReplyUp
ExWorkProcRetcode ExCatpoundStmtTcb::workCancel()
{
// Check the down queue from the parent for cancellations. Propagate
// cancel requests and remove all requests that are completely cancelled.
// Loop over all requests that have been sent down.
queue_index x;
for (x = qparent_.down->getHeadIndex(); x != parent2leftx_; x++) {
ex_queue_entry *pentry = qparent_.down->getQueueEntry(x);
// check whether the current down request is cancelled
if (pentry->downState.request == ex_queue::GET_NOMORE) {
ExCatpoundStmtPrivateState &pstate =
*((ExCatpoundStmtPrivateState*)pentry->pstate);
if (pstate.leftstate_ == CS_STARTED ||
pstate.leftstate_ == CS_NOT_EMPTY) {
// cancel request to left child
qleft_.down->cancelRequestWithParentIndex(x);
pstate.leftstate_ = CS_CANCELLED;
}
if (pstate.rightstate_ == CS_STARTED ||
pstate.rightstate_ == CS_NOT_EMPTY) {
// cancel request to right child
qright_.down->cancelRequestWithParentIndex(x);
pstate.rightstate_ = CS_CANCELLED;
}
}
}
return WORK_OK;
} // ExCatpoundStmtTcb::workCancel
// Process and propagate error up to parent's up-queue
void ExCatpoundStmtTcb::processError(atp_struct *atp, ComDiagsArea *da)
{
ex_queue_entry *pdentry = qparent_.down->getHeadEntry();
ex_queue_entry *puentry = qparent_.up->getTailEntry();
ExCatpoundStmtPrivateState &pstate =
*((ExCatpoundStmtPrivateState*)pdentry->pstate);
// set up error entry for parent up-queue
puentry->copyAtp(atp);
puentry->upState.status = ex_queue::Q_SQLERROR;
puentry->upState.parentIndex = pdentry->downState.parentIndex;
puentry->upState.downIndex = qparent_.down->getHeadIndex();
puentry->upState.setMatchNo(pstate.rightrows_);
if (da) puentry->setDiagsAreax(da);
// insert entry into parent's up queue
qparent_.up->insert();
// cancel this request and all its children
qparent_.down->cancelRequest(qparent_.down->getHeadIndex());
workCancel();
} // ExCatpoundStmtTcb::processError
// Process CS error due to a child returning > 1 row.
void ExCatpoundStmtTcb::processCardinalityError(ex_queue_entry *centry)
{
// create error for diags
ComDiagsArea *da = ExRaiseSqlError
(getGlobals()->getDefaultHeap(), centry,
(ExeErrorCode)-EXE_BLOCK_CARDINALITY_VIOLATION);
processError(centry->getAtp(), da);
} // ExCatpoundStmtTcb::processCardinalityError
//This method is used to raise error -EXE_CS_EOD_ROLLBACK_ERROR or
// warning +EXE_CS_EOD. Raising this error or warning causes further processing of the
// CS to be stopped and if any updates were seen previously in this CS then the
// whole transaction is rolled back. Note that the warning EXE_CS_EOD is actually
//raised as an error here and and attached to a Q_SQLERROR entry. It is converted into a
//warning in the root::fetch or root::oltExecute method. This is done since it
//is crucial that this warning be posted and further processing on the offending CS be stopped.
//There is a possibility that warnings are not propogated correctly and we continue processing
//on the CS once the warning has been raised as an actual warning.
void ExCatpoundStmtTcb::processEODErrorOrWarning(NABoolean isWarning)
{
ex_queue_entry *pdentry = qparent_.down->getHeadEntry();
ex_queue_entry *puentry = qparent_.up->getTailEntry();
ComDiagsArea * da ;
if (isWarning)
da = ExRaiseSqlError(getGlobals()->getDefaultHeap(), puentry,
(ExeErrorCode)-EXE_CS_EOD);
else
da = ExRaiseSqlError(getGlobals()->getDefaultHeap(), puentry,
(ExeErrorCode)-EXE_CS_EOD_ROLLBACK_ERROR);
puentry->setDiagsAreax(da);
puentry->upState.status = ex_queue::Q_SQLERROR;
puentry->upState.parentIndex = pdentry->downState.parentIndex;
puentry->upState.downIndex = qparent_.down->getHeadIndex();
puentry->upState.setMatchNo((Lng32)0);
qparent_.up->insert();
}
//////////////////////////////////////////////////////////////////////////////
// CatpoundStmtPrivateState methods.
//////////////////////////////////////////////////////////////////////////////
void ExCatpoundStmtPrivateState::init()
{
leftstate_ = ExCatpoundStmtTcb::CS_EMPTY;
rightstate_ = ExCatpoundStmtTcb::CS_EMPTY;
leftrows_ = 0;
rightrows_ = 0;
} // void ExCatpoundStmtPrivateState::init
ex_tcb_private_state*
ExCatpoundStmtPrivateState::allocate_new(const ex_tcb *tcb)
{
return new(((ex_tcb *)tcb)->getSpace())
ExCatpoundStmtPrivateState((ExCatpoundStmtTcb *) tcb);
} // ExCatpoundStmtPrivateState::allocate_new