-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.c
722 lines (649 loc) · 20.3 KB
/
main.c
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
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
/*
* main.c
*
* Entrypoint of PG-Strom extension, and misc uncategolized functions.
* ----
* Copyright 2011-2014 (C) KaiGai Kohei <[email protected]>
* Copyright 2014 (C) The PG-Strom Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "postgres.h"
#include "fmgr.h"
#include "miscadmin.h"
#include "optimizer/clauses.h"
#include "optimizer/cost.h"
#include "storage/ipc.h"
#include "storage/shmem.h"
#include "utils/builtins.h"
#include "utils/guc.h"
#include <float.h>
#include <limits.h>
#include "pg_strom.h"
PG_MODULE_MAGIC;
/*
* miscellaneous GUC parameters
*/
static bool guc_pgstrom_enabled;
static bool guc_pgstrom_enabled_global;
bool pgstrom_perfmon_enabled;
bool pgstrom_show_device_kernel;
int pgstrom_chunk_size;
int pgstrom_max_async_chunks;
int pgstrom_min_async_chunks;
/* cost factors */
double pgstrom_gpu_setup_cost;
double pgstrom_gpu_operator_cost;
double pgstrom_gpu_tuple_cost;
/*
* global_guc_values - segment for global GUC variables
*
* pg_strom.enabled_global turns on/off PG-Strom functionality of
* all the concurrent backend, for test/benchmark purpose mainly.
*/
static shmem_startup_hook_type shmem_startup_hook_next = NULL;
static struct {
slock_t lock;
bool pgstrom_enabled_global;
} *global_guc_values = NULL;
/*
* wrapper of pg_strom.enabled and pg_strom.enabled_global configuration
*/
bool
pgstrom_enabled(void)
{
bool rc = false;
if (guc_pgstrom_enabled)
{
SpinLockAcquire(&global_guc_values->lock);
rc = global_guc_values->pgstrom_enabled_global;
SpinLockRelease(&global_guc_values->lock);
}
return rc;
}
/*
* assign callback of pg_strom.enabled_global
*/
static void
pg_strom_enabled_global_assign(bool newval, void *extra)
{
SpinLockAcquire(&global_guc_values->lock);
global_guc_values->pgstrom_enabled_global = newval;
SpinLockRelease(&global_guc_values->lock);
}
/*
* show callback of pg_strom.enabled_global
*/
static const char *
pg_strom_enabled_global_show(void)
{
bool rc;
SpinLockAcquire(&global_guc_values->lock);
rc = global_guc_values->pgstrom_enabled_global;
SpinLockRelease(&global_guc_values->lock);
return rc ? "on" : "off";
}
static void
pgstrom_init_misc_guc(void)
{
/* GUC variables according to the device information */
DefineCustomBoolVariable("pg_strom.enabled",
"Enables the planner's use of PG-Strom",
NULL,
&guc_pgstrom_enabled,
true,
PGC_USERSET,
GUC_NOT_IN_SAMPLE,
NULL, NULL, NULL);
DefineCustomBoolVariable("pg_strom.perfmon",
"Enables the performance monitor of PG-Strom",
NULL,
&pgstrom_perfmon_enabled,
false,
PGC_USERSET,
GUC_NOT_IN_SAMPLE,
NULL, NULL, NULL);
DefineCustomBoolVariable("pg_strom.show_device_kernel",
"Enables to show device kernel on EXPLAIN",
NULL,
&pgstrom_show_device_kernel,
false,
PGC_USERSET,
GUC_NOT_IN_SAMPLE,
NULL, NULL, NULL);
DefineCustomIntVariable("pg_strom.chunk_size",
"default size of pgstrom_data_store in MB",
NULL,
&pgstrom_chunk_size,
15,
4,
128,
PGC_USERSET,
GUC_NOT_IN_SAMPLE,
NULL, NULL, NULL);
DefineCustomIntVariable("pg_strom.min_async_chunks",
"least number of chunks to be run asynchronously",
NULL,
&pgstrom_min_async_chunks,
2,
2,
INT_MAX,
PGC_USERSET,
GUC_NOT_IN_SAMPLE,
NULL, NULL, NULL);
DefineCustomIntVariable("pg_strom.max_async_chunks",
"max number of chunk to be run asynchronously",
NULL,
&pgstrom_max_async_chunks,
3,
pgstrom_min_async_chunks + 1,
INT_MAX,
PGC_USERSET,
GUC_NOT_IN_SAMPLE,
NULL, NULL, NULL);
if (pgstrom_max_async_chunks <= pgstrom_min_async_chunks)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("\"pg_strom.max_async_chunks\" must be larger than \"pg_strom.min_async_chunks\"")));
DefineCustomRealVariable("gpu_setup_cost",
"Cost to setup GPU device to run",
NULL,
&pgstrom_gpu_setup_cost,
500 * DEFAULT_SEQ_PAGE_COST,
0,
DBL_MAX,
PGC_USERSET,
GUC_NOT_IN_SAMPLE,
NULL, NULL, NULL);
DefineCustomRealVariable("gpu_operator_cost",
"Cost of processing each operators by GPU",
NULL,
&pgstrom_gpu_operator_cost,
DEFAULT_CPU_OPERATOR_COST / 100.0,
0,
DBL_MAX,
PGC_USERSET,
GUC_NOT_IN_SAMPLE,
NULL, NULL, NULL);
DefineCustomRealVariable("gpu_tuple_cost",
"Cost of processing each tuple for GPU",
NULL,
&pgstrom_gpu_tuple_cost,
DEFAULT_CPU_TUPLE_COST / 32,
0,
DBL_MAX,
PGC_USERSET,
GUC_NOT_IN_SAMPLE,
NULL, NULL, NULL);
}
/*
* pgstrom_startup_global_guc
*
* allocation of shared memory for global guc
*/
static void
pgstrom_startup_global_guc(void)
{
bool found;
if (shmem_startup_hook_next)
(*shmem_startup_hook_next)();
global_guc_values = ShmemInitStruct("pg_strom: global_guc",
MAXALIGN(sizeof(*global_guc_values)),
&found);
Assert(!found);
/* segment initialization */
memset(global_guc_values, 0, MAXALIGN(sizeof(*global_guc_values)));
SpinLockInit(&global_guc_values->lock);
/* add pg_strom.enabled_global parameter */
DefineCustomBoolVariable("pg_strom.enabled_global",
"Enables the planner's use of PG-Strom in global",
NULL,
&guc_pgstrom_enabled_global,
true,
PGC_SUSET,
GUC_NOT_IN_SAMPLE |
GUC_SUPERUSER_ONLY,
NULL,
pg_strom_enabled_global_assign,
pg_strom_enabled_global_show);
}
void
_PG_init(void)
{
/*
* PG-Strom has to be loaded using shared_preload_libraries option
*/
if (!process_shared_preload_libraries_in_progress)
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("PG-Strom must be loaded via shared_preload_libraries")));
/* load OpenCL runtime and initialize entrypoints */
pgstrom_init_opencl_entry();
/* initialization of device info on postmaster stage */
pgstrom_init_opencl_devinfo();
pgstrom_init_opencl_devprog();
/* initialization of message queue on postmaster stage */
pgstrom_init_mqueue();
/* initialization of resource tracking subsystem */
pgstrom_init_restrack();
/* initialize shared memory segment and memory context stuff */
pgstrom_init_shmem();
/* registration of OpenCL background worker process */
pgstrom_init_opencl_server();
/* registration of custom-plan providers */
pgstrom_init_gpuscan();
pgstrom_init_gpuhashjoin();
pgstrom_init_gpupreagg();
/* miscellaneous initializations */
pgstrom_init_misc_guc();
pgstrom_init_codegen();
pgstrom_init_grafter();
/* allocation of shared memory */
RequestAddinShmemSpace(MAXALIGN(sizeof(*global_guc_values)));
shmem_startup_hook_next = shmem_startup_hook;
shmem_startup_hook = pgstrom_startup_global_guc;
}
/*
* pgstrom_strerror
*
* translation from StromError_* to human readable form
*/
const char *
pgstrom_strerror(cl_int errcode)
{
static char unknown_buf[256];
if (errcode < 0)
return opencl_strerror(errcode);
switch (errcode)
{
case StromError_Success:
return "Success";
case StromError_RowFiltered:
return "Row is filtered";
case StromError_CpuReCheck:
return "To be re-checked by CPU";
case StromError_ServerNotReady:
return "OpenCL server is not ready";
case StromError_BadRequestMessage:
return "Request message is bad";
case StromError_OpenCLInternal:
return "OpenCL internal error";
case StromError_OutOfSharedMemory:
return "out of shared memory";
case StromError_OutOfMemory:
return "out of host memory";
case StromError_DataStoreCorruption:
return "data store is corrupted";
case StromError_DataStoreNoSpace:
return "data store has no space";
case StromError_DataStoreOutOfRange:
return "out of range in data store";
case StromError_SanityCheckViolation:
return "sanity check violation";
default:
snprintf(unknown_buf, sizeof(unknown_buf),
"undefined strom error (code: %d)", errcode);
break;
}
return unknown_buf;
}
/* ------------------------------------------------------------
*
* Routines copied from core PostgreSQL implementation
*
* ------------------------------------------------------------
*/
void
show_scan_qual(List *qual, const char *qlabel,
PlanState *planstate, List *ancestors,
ExplainState *es)
{
bool useprefix;
Node *node;
List *context;
char *exprstr;
useprefix = (IsA(planstate->plan, SubqueryScan) || es->verbose);
/* No work if empty qual */
if (qual == NIL)
return;
/* Convert AND list to explicit AND */
node = (Node *) make_ands_explicit(qual);
/* Set up deparsing context */
context = deparse_context_for_planstate((Node *) planstate,
ancestors,
es->rtable,
es->rtable_names);
/* Deparse the expression */
exprstr = deparse_expression(node, context, useprefix, false);
/* And add to es->str */
ExplainPropertyText(qlabel, exprstr, es);
}
/*
* If it's EXPLAIN ANALYZE, show instrumentation information for a plan node
*
* "which" identifies which instrumentation counter to print
*/
void
show_instrumentation_count(const char *qlabel, int which,
PlanState *planstate, ExplainState *es)
{
double nfiltered;
double nloops;
if (!es->analyze || !planstate->instrument)
return;
if (which == 2)
nfiltered = planstate->instrument->nfiltered2;
else
nfiltered = planstate->instrument->nfiltered1;
nloops = planstate->instrument->nloops;
/* In text mode, suppress zero counts; they're not interesting enough */
if (nfiltered > 0 || es->format != EXPLAIN_FORMAT_TEXT)
{
if (nloops > 0)
ExplainPropertyFloat(qlabel, nfiltered / nloops, 0, es);
else
ExplainPropertyFloat(qlabel, 0.0, 0, es);
}
}
void
show_device_kernel(Datum dprog_key, ExplainState *es)
{
StringInfoData str;
const char *kernel_source;
int32 extra_flags;
if (!dprog_key || !es->verbose || !pgstrom_show_device_kernel)
return;
kernel_source = pgstrom_get_devprog_kernel_source(dprog_key);
extra_flags = pgstrom_get_devprog_extra_flags(dprog_key);
initStringInfo(&str);
/*
* In case of EXPLAIN command context, we show the built-in logics
* like a usual #include preprocessor command.
* Practically, clCreateProgramWithSource() accepts multiple cstrings
* as if external files are included.
*/
appendStringInfo(&str, "#include \"opencl_common.h\"\n");
if (extra_flags & DEVKERNEL_NEEDS_GPUSCAN)
appendStringInfo(&str, "#include \"opencl_gpuscan.h\"\n");
if (extra_flags & DEVKERNEL_NEEDS_HASHJOIN)
appendStringInfo(&str, "#include \"opencl_hashjoin.h\"\n");
if (extra_flags & DEVKERNEL_NEEDS_GPUPREAGG)
appendStringInfo(&str, "#include \"opencl_gpupreagg.h\"\n");
if (extra_flags & DEVFUNC_NEEDS_MATHLIB)
appendStringInfo(&str, "#include \"opencl_mathlib.h\"\n");
if (extra_flags & DEVFUNC_NEEDS_TIMELIB)
appendStringInfo(&str, "#include \"opencl_timelib.h\"\n");
if (extra_flags & DEVFUNC_NEEDS_TEXTLIB)
appendStringInfo(&str, "#include \"opencl_textlib.h\"\n");
if (extra_flags & DEVFUNC_NEEDS_NUMERIC)
appendStringInfo(&str, "#include \"opencl_numeric.h\"\n");
appendStringInfo(&str, "\n%s", kernel_source);
ExplainPropertyText("Kernel Source", str.data, es);
pfree(str.data);
}
void
pgstrom_perfmon_add(pgstrom_perfmon *pfm_sum, pgstrom_perfmon *pfm_item)
{
if (!pfm_sum->enabled)
return;
pfm_sum->num_samples++;
pfm_sum->time_inner_load += pfm_item->time_inner_load;
pfm_sum->time_outer_load += pfm_item->time_outer_load;
pfm_sum->time_materialize += pfm_item->time_materialize;
pfm_sum->time_in_sendq += pfm_item->time_in_sendq;
pfm_sum->time_in_recvq += pfm_item->time_in_recvq;
pfm_sum->time_kern_build = Max(pfm_sum->time_kern_build,
pfm_item->time_kern_build);
pfm_sum->num_dma_send += pfm_item->num_dma_send;
pfm_sum->num_dma_recv += pfm_item->num_dma_recv;
pfm_sum->bytes_dma_send += pfm_item->bytes_dma_send;
pfm_sum->bytes_dma_recv += pfm_item->bytes_dma_recv;
pfm_sum->time_dma_send += pfm_item->time_dma_send;
pfm_sum->time_dma_recv += pfm_item->time_dma_recv;
pfm_sum->num_kern_exec += pfm_item->num_kern_exec;
pfm_sum->time_kern_exec += pfm_item->time_kern_exec;
/* for gpuhashjoin */
pfm_sum->num_kern_proj += pfm_item->num_kern_proj;
pfm_sum->time_kern_proj += pfm_item->time_kern_proj;
/* for gpupreagg */
pfm_sum->num_kern_prep += pfm_item->num_kern_prep;
pfm_sum->num_kern_sort += pfm_item->num_kern_sort;
pfm_sum->time_kern_prep += pfm_item->time_kern_prep;
pfm_sum->time_kern_sort += pfm_item->time_kern_sort;
/* for debugging */
pfm_sum->time_debug1 += pfm_item->time_debug1;
pfm_sum->time_debug2 += pfm_item->time_debug2;
pfm_sum->time_debug3 += pfm_item->time_debug3;
pfm_sum->time_debug4 += pfm_item->time_debug4;
}
static char *
bytesz_unitary_format(double nbytes)
{
if (nbytes > (double)(1UL << 43))
return psprintf("%.2fTB", nbytes / (double)(1UL << 40));
else if (nbytes > (double)(1UL << 33))
return psprintf("%.2fGB", nbytes / (double)(1UL << 30));
else if (nbytes > (double)(1UL << 23))
return psprintf("%.2fMB", nbytes / (double)(1UL << 20));
else if (nbytes > (double)(1UL << 13))
return psprintf("%.2fKB", nbytes / (double)(1UL << 10));
return psprintf("%uB", (unsigned int)nbytes);
}
static char *
usecond_unitary_format(double usecond)
{
if (usecond > 300.0 * 1000.0 * 1000.0)
return psprintf("%.2fmin", usecond / (60.0 * 1000.0 * 1000.0));
else if (usecond > 8000.0 * 1000.0)
return psprintf("%.2fsec", usecond / (1000.0 * 1000.0));
else if (usecond > 8000.0)
return psprintf("%.2fms", usecond / 1000.0);
return psprintf("%uus", (unsigned int)usecond);
}
void
pgstrom_perfmon_explain(pgstrom_perfmon *pfm, ExplainState *es)
{
bool multi_kernel = false;
char buf[256];
if (!pfm->enabled || pfm->num_samples == 0)
return;
/* common performance statistics */
ExplainPropertyInteger("number of requests", pfm->num_samples, es);
if (pfm->time_inner_load > 0)
{
snprintf(buf, sizeof(buf), "%s",
usecond_unitary_format((double)pfm->time_inner_load));
ExplainPropertyText("total time for inner load", buf, es);
snprintf(buf, sizeof(buf), "%s",
usecond_unitary_format((double)pfm->time_outer_load));
ExplainPropertyText("total time for outer load", buf, es);
}
else
{
snprintf(buf, sizeof(buf), "%s",
usecond_unitary_format((double)pfm->time_outer_load));
ExplainPropertyText("total time to load", buf, es);
}
if (pfm->time_materialize > 0)
{
snprintf(buf, sizeof(buf), "%s",
usecond_unitary_format((double)pfm->time_materialize));
ExplainPropertyText("total time to materialize", buf, es);
}
if (pfm->num_samples > 0 && (pfm->time_in_sendq > 0 ||
pfm->time_in_recvq > 0))
{
snprintf(buf, sizeof(buf), "%s",
usecond_unitary_format((double)pfm->time_in_sendq /
(double)pfm->num_samples));
ExplainPropertyText("average time in send-mq", buf, es);
snprintf(buf, sizeof(buf), "%s",
usecond_unitary_format((double)pfm->time_in_recvq /
(double)pfm->num_samples));
ExplainPropertyText("average time in recv-mq", buf, es);
}
if (pfm->time_kern_build > 0)
{
snprintf(buf, sizeof(buf), "%s",
usecond_unitary_format((double)pfm->time_kern_build));
ExplainPropertyText("max time to build kernel", buf, es);
}
if (pfm->num_dma_send > 0)
{
double band = (((double)pfm->bytes_dma_send * 1000000.0)
/ (double)pfm->time_dma_send);
snprintf(buf, sizeof(buf),
"%s/sec, len: %s, time: %s, count: %u",
bytesz_unitary_format(band),
bytesz_unitary_format((double)pfm->bytes_dma_send),
usecond_unitary_format((double)pfm->time_dma_send),
pfm->num_dma_send);
ExplainPropertyText("DMA send", buf, es);
}
if (pfm->num_dma_recv > 0)
{
double band = (((double)pfm->bytes_dma_recv * 1000000.0)
/ (double)pfm->time_dma_recv);
snprintf(buf, sizeof(buf),
"%s/sec, len: %s, time: %s, count: %u",
bytesz_unitary_format(band),
bytesz_unitary_format((double)pfm->bytes_dma_recv),
usecond_unitary_format((double)pfm->time_dma_recv),
pfm->num_dma_recv);
ExplainPropertyText("DMA recv", buf, es);
}
/* only gpupreagg */
if (pfm->num_kern_prep > 0)
{
multi_kernel = true;
snprintf(buf, sizeof(buf), "total: %s, avg: %s, count: %u",
usecond_unitary_format((double)pfm->time_kern_prep),
usecond_unitary_format((double)pfm->time_kern_prep /
(double)pfm->num_kern_prep),
pfm->num_kern_prep);
ExplainPropertyText("prep kernel exec", buf, es);
}
/* only gpupreagg */
if (pfm->num_kern_sort > 0)
{
multi_kernel = true;
snprintf(buf, sizeof(buf), "total: %s, avg: %s, count: %u",
usecond_unitary_format((double)pfm->time_kern_sort),
usecond_unitary_format((double)pfm->time_kern_sort /
(double)pfm->num_kern_sort),
pfm->num_kern_sort);
ExplainPropertyText("sort kernel exec", buf, es);
}
/* only gpuhashjoin */
if (pfm->num_kern_proj > 0)
{
multi_kernel = true;
snprintf(buf, sizeof(buf), "total: %s, avg: %s, count: %u",
usecond_unitary_format((double)pfm->time_kern_proj),
usecond_unitary_format((double)pfm->time_kern_proj /
(double)pfm->num_kern_proj),
pfm->num_kern_exec);
ExplainPropertyText("proj kernel exec", buf, es);
}
if (pfm->num_kern_exec > 0)
{
const char *label =
(multi_kernel ? "main kernel exec" : "kernel exec");
snprintf(buf, sizeof(buf), "total: %s, avg: %s, count: %u",
usecond_unitary_format((double)pfm->time_kern_exec),
usecond_unitary_format((double)pfm->time_kern_exec /
(double)pfm->num_kern_exec),
pfm->num_kern_exec);
ExplainPropertyText(label, buf, es);
}
/* for debugging if any */
if (pfm->time_debug1 > 0)
{
snprintf(buf, sizeof(buf), "debug1: %s",
usecond_unitary_format((double)pfm->time_debug1));
ExplainPropertyText("debug-1", buf, es);
}
if (pfm->time_debug2 > 0)
{
snprintf(buf, sizeof(buf), "debug2: %s",
usecond_unitary_format((double)pfm->time_debug2));
ExplainPropertyText("debug-2", buf, es);
}
if (pfm->time_debug3 > 0)
{
snprintf(buf, sizeof(buf), "debug3: %s",
usecond_unitary_format((double)pfm->time_debug3));
ExplainPropertyText("debug-3", buf, es);
}
if (pfm->time_debug4 > 0)
{
snprintf(buf, sizeof(buf), "debug4: %s",
usecond_unitary_format((double)pfm->time_debug4));
ExplainPropertyText("debug-4", buf, es);
}
}
/*
* XXX - copied from outfuncs.c
*
* _outToken
* Convert an ordinary string (eg, an identifier) into a form that
* will be decoded back to a plain token by read.c's functions.
*
* If a null or empty string is given, it is encoded as "<>".
*/
void
_outToken(StringInfo str, const char *s)
{
if (s == NULL || *s == '\0')
{
appendStringInfoString(str, "<>");
return;
}
/*
* Look for characters or patterns that are treated specially by read.c
* (either in pg_strtok() or in nodeRead()), and therefore need a
* protective backslash.
*/
/* These characters only need to be quoted at the start of the string */
if (*s == '<' ||
*s == '\"' ||
isdigit((unsigned char) *s) ||
((*s == '+' || *s == '-') &&
(isdigit((unsigned char) s[1]) || s[1] == '.')))
appendStringInfoChar(str, '\\');
while (*s)
{
/* These chars must be backslashed anywhere in the string */
if (*s == ' ' || *s == '\n' || *s == '\t' ||
*s == '(' || *s == ')' || *s == '{' || *s == '}' ||
*s == '\\')
appendStringInfoChar(str, '\\');
appendStringInfoChar(str, *s++);
}
}
/*
* _outBitmapset -
* converts a bitmap set of integers
*
* Note: the output format is "(b int int ...)", similar to an integer List.
*/
void
_outBitmapset(StringInfo str, const Bitmapset *bms)
{
Bitmapset *tmpset;
int x;
appendStringInfoChar(str, '(');
appendStringInfoChar(str, 'b');
tmpset = bms_copy(bms);
while ((x = bms_first_member(tmpset)) >= 0)
appendStringInfo(str, " %d", x);
bms_free(tmpset);
appendStringInfoChar(str, ')');
}