/ Check-in [e9fcb793]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Do not release registers used to hold the results of a compound select after just the first select has run. Ticket #2927. For now, we will never release the registers used to hold the result set, since the same register set will be used for each select. This is not an unacceptable register leak and it is the safest approach. (CVS 4778)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e9fcb793998be07eaea01404407087b71c29853d
User & Date: drh 2008-02-06 23:52:37
Context
2008-02-08
18:25
Change the test code used for speed tests so that it does not throw an exception if the time command returns "0 microseconds per iteration". (CVS 4779) check-in: f37e8637 user: danielk1977 tags: trunk
2008-02-06
23:52
Do not release registers used to hold the results of a compound select after just the first select has run. Ticket #2927. For now, we will never release the registers used to hold the result set, since the same register set will be used for each select. This is not an unacceptable register leak and it is the safest approach. (CVS 4778) check-in: e9fcb793 user: drh tags: trunk
16:58
Version 3.5.6 (CVS 4777) check-in: 1d82ab69 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/select.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
...
538
539
540
541
542
543
544
545
546
547
548
549
550
551

552
553
554
555
556
557
558
...
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
...
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.411 2008/01/25 15:04:50 drh Exp $
*/
#include "sqliteInt.h"


/*
** Delete all the content of a Select structure but do not deallocate
** the select structure itself.
................................................................................
  Vdbe *v = pParse->pVdbe;
  int i;
  int hasDistinct;        /* True if the DISTINCT keyword is present */
  int regResult;              /* Start of memory holding result set */
  int eDest = pDest->eDest;   /* How to dispose of results */
  int iParm = pDest->iParm;   /* First argument to disposal method */
  int nResultCol;             /* Number of result columns */
  int nToFree;                /* Number of result columns to release */

  if( v==0 ) return;
  assert( pEList!=0 );

  /* If there was a LIMIT clause on the SELECT statement, then do the check
  ** to see if this row should be output.
  */
................................................................................
  /* Pull the requested columns.
  */
  if( nColumn>0 ){
    nResultCol = nColumn;
  }else{
    nResultCol = pEList->nExpr;
  }
  if( pDest->iMem>0 ){
    regResult = pDest->iMem;
    nToFree = 0;
  }else{
    pDest->iMem = regResult = sqlite3GetTempRange(pParse, nResultCol);
    nToFree = nResultCol;
  }

  if( nColumn>0 ){
    for(i=0; i<nColumn; i++){
      sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
    }
  }else if( eDest!=SRT_Exists ){
    /* If the destination is an EXISTS(...) expression, the actual
    ** values returned by the SELECT are not required.
................................................................................
    case SRT_Callback: {
      if( pOrderBy ){
        int r1 = sqlite3GetTempReg(pParse);
        sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nColumn, r1);
        pushOntoSorter(pParse, pOrderBy, p, r1);
        sqlite3ReleaseTempReg(pParse, r1);
      }else if( eDest==SRT_Subroutine ){
        nToFree = 0;  /* Preserve registers. Subroutine will need them. */
        sqlite3VdbeAddOp2(v, OP_Gosub, 0, iParm);
      }else{
        sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, nColumn);
      }
      break;
    }

................................................................................

  /* Jump to the end of the loop if the LIMIT is reached.
  */
  if( p->iLimit>=0 && pOrderBy==0 ){
    sqlite3VdbeAddOp2(v, OP_AddImm, p->iLimit, -1);
    sqlite3VdbeAddOp2(v, OP_IfZero, p->iLimit, iBreak);
  }
  sqlite3ReleaseTempRange(pParse, regResult, nToFree);
}

/*
** Given an expression list, generate a KeyInfo structure that records
** the collating sequence for each expression in that expression list.
**
** If the ExprList is an ORDER BY or GROUP BY clause then the resulting







|







 







<







 







|
<
<
<
|
<

>







 







<







 







<







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
518
519
520
521
522
523
524

525
526
527
528
529
530
531
...
537
538
539
540
541
542
543
544



545

546
547
548
549
550
551
552
553
554
...
686
687
688
689
690
691
692

693
694
695
696
697
698
699
...
712
713
714
715
716
717
718

719
720
721
722
723
724
725
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.412 2008/02/06 23:52:37 drh Exp $
*/
#include "sqliteInt.h"


/*
** Delete all the content of a Select structure but do not deallocate
** the select structure itself.
................................................................................
  Vdbe *v = pParse->pVdbe;
  int i;
  int hasDistinct;        /* True if the DISTINCT keyword is present */
  int regResult;              /* Start of memory holding result set */
  int eDest = pDest->eDest;   /* How to dispose of results */
  int iParm = pDest->iParm;   /* First argument to disposal method */
  int nResultCol;             /* Number of result columns */


  if( v==0 ) return;
  assert( pEList!=0 );

  /* If there was a LIMIT clause on the SELECT statement, then do the check
  ** to see if this row should be output.
  */
................................................................................
  /* Pull the requested columns.
  */
  if( nColumn>0 ){
    nResultCol = nColumn;
  }else{
    nResultCol = pEList->nExpr;
  }
  if( pDest->iMem==0 ){



    pDest->iMem = sqlite3GetTempRange(pParse, nResultCol);

  }
  regResult = pDest->iMem;
  if( nColumn>0 ){
    for(i=0; i<nColumn; i++){
      sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
    }
  }else if( eDest!=SRT_Exists ){
    /* If the destination is an EXISTS(...) expression, the actual
    ** values returned by the SELECT are not required.
................................................................................
    case SRT_Callback: {
      if( pOrderBy ){
        int r1 = sqlite3GetTempReg(pParse);
        sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nColumn, r1);
        pushOntoSorter(pParse, pOrderBy, p, r1);
        sqlite3ReleaseTempReg(pParse, r1);
      }else if( eDest==SRT_Subroutine ){

        sqlite3VdbeAddOp2(v, OP_Gosub, 0, iParm);
      }else{
        sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, nColumn);
      }
      break;
    }

................................................................................

  /* Jump to the end of the loop if the LIMIT is reached.
  */
  if( p->iLimit>=0 && pOrderBy==0 ){
    sqlite3VdbeAddOp2(v, OP_AddImm, p->iLimit, -1);
    sqlite3VdbeAddOp2(v, OP_IfZero, p->iLimit, iBreak);
  }

}

/*
** Given an expression list, generate a KeyInfo structure that records
** the collating sequence for each expression in that expression list.
**
** If the ExprList is an ORDER BY or GROUP BY clause then the resulting

Added test/tkt2927.test.





























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
# 2008 Feb 6
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# This file is to test that ticket #2927 is fixed.
#
# $Id: tkt2927.test,v 1.1 2008/02/06 23:52:37 drh Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Create a database.
#
do_test tkt2927-1.1 {
  db eval {
    CREATE TABLE t1(a, b);
    INSERT INTO t1 VALUES(1,11);
    INSERT INTO t1 VALUES(2,22);
    INSERT INTO t1 VALUES(3,33);
    INSERT INTO t1 VALUES(4,44);
    INSERT INTO t1 VALUES(5,55);
    SELECT * FROM t1;
  }
} {1 11 2 22 3 33 4 44 5 55}


do_test tkt2927-2.1 {
  db eval {
    SELECT a, b FROM t1
    UNION ALL
    SELECT a, b FROM t1
  }
} {1 11 2 22 3 33 4 44 5 55 1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-2.2 {
breakpoint
#set sqlite_addop_trace 1
  db eval {
    SELECT a, b FROM t1
    UNION ALL
    SELECT a, abs(b) FROM t1
  }
} {1 11 2 22 3 33 4 44 5 55 1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-2.3 {
  db eval {
    SELECT a, b FROM t1
    UNION ALL
    SELECT abs(a), b FROM t1
  }
} {1 11 2 22 3 33 4 44 5 55 1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-2.4 {
  db eval {
    SELECT a, b FROM t1
    UNION ALL
    SELECT abs(a), abs(b) FROM t1
  }
} {1 11 2 22 3 33 4 44 5 55 1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-2.5 {
  db eval {
    SELECT a, abs(b) FROM t1
    UNION ALL
    SELECT a, b FROM t1
  }
} {1 11 2 22 3 33 4 44 5 55 1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-2.6 {
  db eval {
    SELECT a, abs(b) FROM t1
    UNION ALL
    SELECT a, abs(b) FROM t1
  }
} {1 11 2 22 3 33 4 44 5 55 1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-2.7 {
  db eval {
    SELECT a, abs(b) FROM t1
    UNION ALL
    SELECT abs(a), b FROM t1
  }
} {1 11 2 22 3 33 4 44 5 55 1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-2.8 {
  db eval {
    SELECT a, abs(b) FROM t1
    UNION ALL
    SELECT abs(a), abs(b) FROM t1
  }
} {1 11 2 22 3 33 4 44 5 55 1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-2.9 {
  db eval {
    SELECT abs(a), b FROM t1
    UNION ALL
    SELECT a, b FROM t1
  }
} {1 11 2 22 3 33 4 44 5 55 1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-2.10 {
  db eval {
    SELECT abs(a), b FROM t1
    UNION ALL
    SELECT a, abs(b) FROM t1
  }
} {1 11 2 22 3 33 4 44 5 55 1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-2.11 {
  db eval {
    SELECT abs(a), b FROM t1
    UNION ALL
    SELECT abs(a), b FROM t1
  }
} {1 11 2 22 3 33 4 44 5 55 1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-2.12 {
  db eval {
    SELECT abs(a), b FROM t1
    UNION ALL
    SELECT abs(a), abs(b) FROM t1
  }
} {1 11 2 22 3 33 4 44 5 55 1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-2.13 {
  db eval {
    SELECT abs(a), abs(b) FROM t1
    UNION ALL
    SELECT a, b FROM t1
  }
} {1 11 2 22 3 33 4 44 5 55 1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-2.14 {
  db eval {
    SELECT abs(a), abs(b) FROM t1
    UNION ALL
    SELECT a, abs(b) FROM t1
  }
} {1 11 2 22 3 33 4 44 5 55 1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-2.15 {
  db eval {
    SELECT abs(a), abs(b) FROM t1
    UNION ALL
    SELECT abs(a), b FROM t1
  }
} {1 11 2 22 3 33 4 44 5 55 1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-2.16 {
  db eval {
    SELECT abs(a), abs(b) FROM t1
    UNION ALL
    SELECT abs(a), abs(b) FROM t1
  }
} {1 11 2 22 3 33 4 44 5 55 1 11 2 22 3 33 4 44 5 55}


do_test tkt2927-3.1 {
  db eval {
    SELECT a, b FROM t1
    UNION 
    SELECT a, b FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-3.2 {
  db eval {
    SELECT a, b FROM t1
    UNION 
    SELECT a, abs(b) FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-3.3 {
  db eval {
    SELECT a, b FROM t1
    UNION 
    SELECT abs(a), b FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-3.4 {
  db eval {
    SELECT a, b FROM t1
    UNION 
    SELECT abs(a), abs(b) FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-3.5 {
  db eval {
    SELECT a, abs(b) FROM t1
    UNION 
    SELECT a, b FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-3.6 {
  db eval {
    SELECT a, abs(b) FROM t1
    UNION 
    SELECT a, abs(b) FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-3.7 {
  db eval {
    SELECT a, abs(b) FROM t1
    UNION 
    SELECT abs(a), b FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-3.8 {
  db eval {
    SELECT a, abs(b) FROM t1
    UNION 
    SELECT abs(a), abs(b) FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-3.9 {
  db eval {
    SELECT abs(a), b FROM t1
    UNION 
    SELECT a, b FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-3.10 {
  db eval {
    SELECT abs(a), b FROM t1
    UNION 
    SELECT a, abs(b) FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-3.11 {
  db eval {
    SELECT abs(a), b FROM t1
    UNION 
    SELECT abs(a), b FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-3.12 {
  db eval {
    SELECT abs(a), b FROM t1
    UNION 
    SELECT abs(a), abs(b) FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-3.13 {
  db eval {
    SELECT abs(a), abs(b) FROM t1
    UNION 
    SELECT a, b FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-3.14 {
  db eval {
    SELECT abs(a), abs(b) FROM t1
    UNION 
    SELECT a, abs(b) FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-3.15 {
  db eval {
    SELECT abs(a), abs(b) FROM t1
    UNION 
    SELECT abs(a), b FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-3.16 {
  db eval {
    SELECT abs(a), abs(b) FROM t1
    UNION 
    SELECT abs(a), abs(b) FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}


do_test tkt2927-4.1 {
  db eval {
    SELECT a+b, a-b, a, b FROM t1
    UNION ALL
    SELECT a+b, a-b, a, b FROM t1
  }
} {12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55 12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55}
do_test tkt2927-4.2 {
  db eval {
    SELECT a+b, a-b, a, b FROM t1
    UNION ALL
    SELECT a+b, a-b, a, abs(b) FROM t1
  }
} {12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55 12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55}
do_test tkt2927-4.3 {
  db eval {
    SELECT a+b, a-b, a, b FROM t1
    UNION ALL
    SELECT a+b, a-b, abs(a), b FROM t1
  }
} {12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55 12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55}
do_test tkt2927-4.4 {
  db eval {
    SELECT a+b, a-b, a, b FROM t1
    UNION ALL
    SELECT a+b, a-b, abs(a), abs(b) FROM t1
  }
} {12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55 12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55}
do_test tkt2927-4.5 {
  db eval {
    SELECT a+b, a-b, a, abs(b) FROM t1
    UNION ALL
    SELECT a+b, a-b, a, b FROM t1
  }
} {12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55 12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55}
do_test tkt2927-4.6 {
  db eval {
    SELECT a+b, a-b, a, abs(b) FROM t1
    UNION ALL
    SELECT a+b, a-b, a, abs(b) FROM t1
  }
} {12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55 12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55}
do_test tkt2927-4.7 {
  db eval {
    SELECT a+b, a-b, a, abs(b) FROM t1
    UNION ALL
    SELECT a+b, a-b, abs(a), b FROM t1
  }
} {12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55 12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55}
do_test tkt2927-4.8 {
  db eval {
    SELECT a+b, a-b, a, abs(b) FROM t1
    UNION ALL
    SELECT a+b, a-b, abs(a), abs(b) FROM t1
  }
} {12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55 12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55}
do_test tkt2927-4.9 {
  db eval {
    SELECT a+b, a-b, abs(a), b FROM t1
    UNION ALL
    SELECT a+b, a-b, a, b FROM t1
  }
} {12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55 12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55}
do_test tkt2927-4.10 {
  db eval {
    SELECT a+b, a-b, abs(a), b FROM t1
    UNION ALL
    SELECT a+b, a-b, a, abs(b) FROM t1
  }
} {12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55 12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55}
do_test tkt2927-4.11 {
  db eval {
    SELECT a+b, a-b, abs(a), b FROM t1
    UNION ALL
    SELECT a+b, a-b, abs(a), b FROM t1
  }
} {12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55 12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55}
do_test tkt2927-4.12 {
  db eval {
    SELECT a+b, a-b, abs(a), b FROM t1
    UNION ALL
    SELECT a+b, a-b, abs(a), abs(b) FROM t1
  }
} {12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55 12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55}
do_test tkt2927-4.13 {
  db eval {
    SELECT a+b, a-b, abs(a), abs(b) FROM t1
    UNION ALL
    SELECT a+b, a-b, a, b FROM t1
  }
} {12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55 12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55}
do_test tkt2927-4.14 {
  db eval {
    SELECT a+b, a-b, abs(a), abs(b) FROM t1
    UNION ALL
    SELECT a+b, a-b, a, abs(b) FROM t1
  }
} {12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55 12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55}
do_test tkt2927-4.15 {
  db eval {
    SELECT a+b, a-b, abs(a), abs(b) FROM t1
    UNION ALL
    SELECT a+b, a-b, abs(a), b FROM t1
  }
} {12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55 12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55}
do_test tkt2927-4.16 {
  db eval {
    SELECT a+b, a-b, abs(a), abs(b) FROM t1
    UNION ALL
    SELECT a+b, a-b, abs(a), abs(b) FROM t1
  }
} {12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55 12 -10 1 11 24 -20 2 22 36 -30 3 33 48 -40 4 44 60 -50 5 55}


do_test tkt2927-5.1 {
  db eval {
    SELECT a, b FROM t1
    EXCEPT
    SELECT a, b FROM t1
  }
} {}
do_test tkt2927-5.2 {
  db eval {
    SELECT a, b FROM t1
    EXCEPT
    SELECT a, abs(b) FROM t1
  }
} {}
do_test tkt2927-5.3 {
  db eval {
    SELECT a, b FROM t1
    EXCEPT
    SELECT abs(a), b FROM t1
  }
} {}
do_test tkt2927-5.4 {
  db eval {
    SELECT a, b FROM t1
    EXCEPT
    SELECT abs(a), abs(b) FROM t1
  }
} {}
do_test tkt2927-5.5 {
  db eval {
    SELECT a, abs(b) FROM t1
    EXCEPT
    SELECT a, b FROM t1
  }
} {}
do_test tkt2927-5.6 {
  db eval {
    SELECT a, abs(b) FROM t1
    EXCEPT
    SELECT a, abs(b) FROM t1
  }
} {}
do_test tkt2927-5.7 {
  db eval {
    SELECT a, abs(b) FROM t1
    EXCEPT
    SELECT abs(a), b FROM t1
  }
} {}
do_test tkt2927-5.8 {
  db eval {
    SELECT a, abs(b) FROM t1
    EXCEPT
    SELECT abs(a), abs(b) FROM t1
  }
} {}
do_test tkt2927-5.9 {
  db eval {
    SELECT abs(a), b FROM t1
    EXCEPT
    SELECT a, b FROM t1
  }
} {}
do_test tkt2927-5.10 {
  db eval {
    SELECT abs(a), b FROM t1
    EXCEPT
    SELECT a, abs(b) FROM t1
  }
} {}
do_test tkt2927-5.11 {
  db eval {
    SELECT abs(a), b FROM t1
    EXCEPT
    SELECT abs(a), b FROM t1
  }
} {}
do_test tkt2927-5.12 {
  db eval {
    SELECT abs(a), b FROM t1
    EXCEPT
    SELECT abs(a), abs(b) FROM t1
  }
} {}
do_test tkt2927-5.13 {
  db eval {
    SELECT abs(a), abs(b) FROM t1
    EXCEPT
    SELECT a, b FROM t1
  }
} {}
do_test tkt2927-5.14 {
  db eval {
    SELECT abs(a), abs(b) FROM t1
    EXCEPT
    SELECT a, abs(b) FROM t1
  }
} {}
do_test tkt2927-5.15 {
  db eval {
    SELECT abs(a), abs(b) FROM t1
    EXCEPT
    SELECT abs(a), b FROM t1
  }
} {}
do_test tkt2927-5.16 {
  db eval {
    SELECT abs(a), abs(b) FROM t1
    EXCEPT
    SELECT abs(a), abs(b) FROM t1
  }
} {}


do_test tkt2927-6.1 {
  db eval {
    SELECT a, b FROM t1
    INTERSECT
    SELECT a, b FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-6.2 {
  db eval {
    SELECT a, b FROM t1
    INTERSECT
    SELECT a, abs(b) FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-6.3 {
  db eval {
    SELECT a, b FROM t1
    INTERSECT
    SELECT abs(a), b FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-6.4 {
  db eval {
    SELECT a, b FROM t1
    INTERSECT
    SELECT abs(a), abs(b) FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-6.5 {
  db eval {
    SELECT a, abs(b) FROM t1
    INTERSECT
    SELECT a, b FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-6.6 {
  db eval {
    SELECT a, abs(b) FROM t1
    INTERSECT
    SELECT a, abs(b) FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-6.7 {
  db eval {
    SELECT a, abs(b) FROM t1
    INTERSECT
    SELECT abs(a), b FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-6.8 {
  db eval {
    SELECT a, abs(b) FROM t1
    INTERSECT
    SELECT abs(a), abs(b) FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-6.9 {
  db eval {
    SELECT abs(a), b FROM t1
    INTERSECT
    SELECT a, b FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-6.10 {
  db eval {
    SELECT abs(a), b FROM t1
    INTERSECT
    SELECT a, abs(b) FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-6.11 {
  db eval {
    SELECT abs(a), b FROM t1
    INTERSECT
    SELECT abs(a), b FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-6.12 {
  db eval {
    SELECT abs(a), b FROM t1
    INTERSECT
    SELECT abs(a), abs(b) FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-6.13 {
  db eval {
    SELECT abs(a), abs(b) FROM t1
    INTERSECT
    SELECT a, b FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-6.14 {
  db eval {
    SELECT abs(a), abs(b) FROM t1
    INTERSECT
    SELECT a, abs(b) FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-6.15 {
  db eval {
    SELECT abs(a), abs(b) FROM t1
    INTERSECT
    SELECT abs(a), b FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}
do_test tkt2927-6.16 {
  db eval {
    SELECT abs(a), abs(b) FROM t1
    INTERSECT
    SELECT abs(a), abs(b) FROM t1
    ORDER BY 1
  }
} {1 11 2 22 3 33 4 44 5 55}

finish_test