PostgreSQL Source Code  git master
int8.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * int8.c
4  * Internal 64-bit integer operations
5  *
6  * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * IDENTIFICATION
10  * src/backend/utils/adt/int8.c
11  *
12  *-------------------------------------------------------------------------
13  */
14 #include "postgres.h"
15 
16 #include <ctype.h>
17 #include <limits.h>
18 #include <math.h>
19 
20 #include "common/int.h"
21 #include "funcapi.h"
22 #include "libpq/pqformat.h"
23 #include "nodes/nodeFuncs.h"
24 #include "nodes/supportnodes.h"
25 #include "optimizer/optimizer.h"
26 #include "utils/builtins.h"
27 #include "utils/lsyscache.h"
28 
29 
30 typedef struct
31 {
32  int64 current;
33  int64 finish;
34  int64 step;
36 
37 
38 /***********************************************************************
39  **
40  ** Routines for 64-bit integers.
41  **
42  ***********************************************************************/
43 
44 /*----------------------------------------------------------
45  * Formatting and conversion routines.
46  *---------------------------------------------------------*/
47 
48 /* int8in()
49  */
50 Datum
52 {
53  char *num = PG_GETARG_CSTRING(0);
54 
56 }
57 
58 
59 /* int8out()
60  */
61 Datum
63 {
64  int64 val = PG_GETARG_INT64(0);
65  char buf[MAXINT8LEN + 1];
66  char *result;
67  int len;
68 
69  len = pg_lltoa(val, buf) + 1;
70 
71  /*
72  * Since the length is already known, we do a manual palloc() and memcpy()
73  * to avoid the strlen() call that would otherwise be done in pstrdup().
74  */
75  result = palloc(len);
76  memcpy(result, buf, len);
77  PG_RETURN_CSTRING(result);
78 }
79 
80 /*
81  * int8recv - converts external binary format to int8
82  */
83 Datum
85 {
87 
89 }
90 
91 /*
92  * int8send - converts int8 to binary format
93  */
94 Datum
96 {
97  int64 arg1 = PG_GETARG_INT64(0);
99 
101  pq_sendint64(&buf, arg1);
103 }
104 
105 
106 /*----------------------------------------------------------
107  * Relational operators for int8s, including cross-data-type comparisons.
108  *---------------------------------------------------------*/
109 
110 /* int8relop()
111  * Is val1 relop val2?
112  */
113 Datum
115 {
116  int64 val1 = PG_GETARG_INT64(0);
117  int64 val2 = PG_GETARG_INT64(1);
118 
119  PG_RETURN_BOOL(val1 == val2);
120 }
121 
122 Datum
124 {
125  int64 val1 = PG_GETARG_INT64(0);
126  int64 val2 = PG_GETARG_INT64(1);
127 
128  PG_RETURN_BOOL(val1 != val2);
129 }
130 
131 Datum
133 {
134  int64 val1 = PG_GETARG_INT64(0);
135  int64 val2 = PG_GETARG_INT64(1);
136 
137  PG_RETURN_BOOL(val1 < val2);
138 }
139 
140 Datum
142 {
143  int64 val1 = PG_GETARG_INT64(0);
144  int64 val2 = PG_GETARG_INT64(1);
145 
146  PG_RETURN_BOOL(val1 > val2);
147 }
148 
149 Datum
151 {
152  int64 val1 = PG_GETARG_INT64(0);
153  int64 val2 = PG_GETARG_INT64(1);
154 
155  PG_RETURN_BOOL(val1 <= val2);
156 }
157 
158 Datum
160 {
161  int64 val1 = PG_GETARG_INT64(0);
162  int64 val2 = PG_GETARG_INT64(1);
163 
164  PG_RETURN_BOOL(val1 >= val2);
165 }
166 
167 /* int84relop()
168  * Is 64-bit val1 relop 32-bit val2?
169  */
170 Datum
172 {
173  int64 val1 = PG_GETARG_INT64(0);
174  int32 val2 = PG_GETARG_INT32(1);
175 
176  PG_RETURN_BOOL(val1 == val2);
177 }
178 
179 Datum
181 {
182  int64 val1 = PG_GETARG_INT64(0);
183  int32 val2 = PG_GETARG_INT32(1);
184 
185  PG_RETURN_BOOL(val1 != val2);
186 }
187 
188 Datum
190 {
191  int64 val1 = PG_GETARG_INT64(0);
192  int32 val2 = PG_GETARG_INT32(1);
193 
194  PG_RETURN_BOOL(val1 < val2);
195 }
196 
197 Datum
199 {
200  int64 val1 = PG_GETARG_INT64(0);
201  int32 val2 = PG_GETARG_INT32(1);
202 
203  PG_RETURN_BOOL(val1 > val2);
204 }
205 
206 Datum
208 {
209  int64 val1 = PG_GETARG_INT64(0);
210  int32 val2 = PG_GETARG_INT32(1);
211 
212  PG_RETURN_BOOL(val1 <= val2);
213 }
214 
215 Datum
217 {
218  int64 val1 = PG_GETARG_INT64(0);
219  int32 val2 = PG_GETARG_INT32(1);
220 
221  PG_RETURN_BOOL(val1 >= val2);
222 }
223 
224 /* int48relop()
225  * Is 32-bit val1 relop 64-bit val2?
226  */
227 Datum
229 {
230  int32 val1 = PG_GETARG_INT32(0);
231  int64 val2 = PG_GETARG_INT64(1);
232 
233  PG_RETURN_BOOL(val1 == val2);
234 }
235 
236 Datum
238 {
239  int32 val1 = PG_GETARG_INT32(0);
240  int64 val2 = PG_GETARG_INT64(1);
241 
242  PG_RETURN_BOOL(val1 != val2);
243 }
244 
245 Datum
247 {
248  int32 val1 = PG_GETARG_INT32(0);
249  int64 val2 = PG_GETARG_INT64(1);
250 
251  PG_RETURN_BOOL(val1 < val2);
252 }
253 
254 Datum
256 {
257  int32 val1 = PG_GETARG_INT32(0);
258  int64 val2 = PG_GETARG_INT64(1);
259 
260  PG_RETURN_BOOL(val1 > val2);
261 }
262 
263 Datum
265 {
266  int32 val1 = PG_GETARG_INT32(0);
267  int64 val2 = PG_GETARG_INT64(1);
268 
269  PG_RETURN_BOOL(val1 <= val2);
270 }
271 
272 Datum
274 {
275  int32 val1 = PG_GETARG_INT32(0);
276  int64 val2 = PG_GETARG_INT64(1);
277 
278  PG_RETURN_BOOL(val1 >= val2);
279 }
280 
281 /* int82relop()
282  * Is 64-bit val1 relop 16-bit val2?
283  */
284 Datum
286 {
287  int64 val1 = PG_GETARG_INT64(0);
288  int16 val2 = PG_GETARG_INT16(1);
289 
290  PG_RETURN_BOOL(val1 == val2);
291 }
292 
293 Datum
295 {
296  int64 val1 = PG_GETARG_INT64(0);
297  int16 val2 = PG_GETARG_INT16(1);
298 
299  PG_RETURN_BOOL(val1 != val2);
300 }
301 
302 Datum
304 {
305  int64 val1 = PG_GETARG_INT64(0);
306  int16 val2 = PG_GETARG_INT16(1);
307 
308  PG_RETURN_BOOL(val1 < val2);
309 }
310 
311 Datum
313 {
314  int64 val1 = PG_GETARG_INT64(0);
315  int16 val2 = PG_GETARG_INT16(1);
316 
317  PG_RETURN_BOOL(val1 > val2);
318 }
319 
320 Datum
322 {
323  int64 val1 = PG_GETARG_INT64(0);
324  int16 val2 = PG_GETARG_INT16(1);
325 
326  PG_RETURN_BOOL(val1 <= val2);
327 }
328 
329 Datum
331 {
332  int64 val1 = PG_GETARG_INT64(0);
333  int16 val2 = PG_GETARG_INT16(1);
334 
335  PG_RETURN_BOOL(val1 >= val2);
336 }
337 
338 /* int28relop()
339  * Is 16-bit val1 relop 64-bit val2?
340  */
341 Datum
343 {
344  int16 val1 = PG_GETARG_INT16(0);
345  int64 val2 = PG_GETARG_INT64(1);
346 
347  PG_RETURN_BOOL(val1 == val2);
348 }
349 
350 Datum
352 {
353  int16 val1 = PG_GETARG_INT16(0);
354  int64 val2 = PG_GETARG_INT64(1);
355 
356  PG_RETURN_BOOL(val1 != val2);
357 }
358 
359 Datum
361 {
362  int16 val1 = PG_GETARG_INT16(0);
363  int64 val2 = PG_GETARG_INT64(1);
364 
365  PG_RETURN_BOOL(val1 < val2);
366 }
367 
368 Datum
370 {
371  int16 val1 = PG_GETARG_INT16(0);
372  int64 val2 = PG_GETARG_INT64(1);
373 
374  PG_RETURN_BOOL(val1 > val2);
375 }
376 
377 Datum
379 {
380  int16 val1 = PG_GETARG_INT16(0);
381  int64 val2 = PG_GETARG_INT64(1);
382 
383  PG_RETURN_BOOL(val1 <= val2);
384 }
385 
386 Datum
388 {
389  int16 val1 = PG_GETARG_INT16(0);
390  int64 val2 = PG_GETARG_INT64(1);
391 
392  PG_RETURN_BOOL(val1 >= val2);
393 }
394 
395 /*
396  * in_range support function for int8.
397  *
398  * Note: we needn't supply int8_int4 or int8_int2 variants, as implicit
399  * coercion of the offset value takes care of those scenarios just as well.
400  */
401 Datum
403 {
404  int64 val = PG_GETARG_INT64(0);
405  int64 base = PG_GETARG_INT64(1);
406  int64 offset = PG_GETARG_INT64(2);
407  bool sub = PG_GETARG_BOOL(3);
408  bool less = PG_GETARG_BOOL(4);
409  int64 sum;
410 
411  if (offset < 0)
412  ereport(ERROR,
413  (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
414  errmsg("invalid preceding or following size in window function")));
415 
416  if (sub)
417  offset = -offset; /* cannot overflow */
418 
419  if (unlikely(pg_add_s64_overflow(base, offset, &sum)))
420  {
421  /*
422  * If sub is false, the true sum is surely more than val, so correct
423  * answer is the same as "less". If sub is true, the true sum is
424  * surely less than val, so the answer is "!less".
425  */
426  PG_RETURN_BOOL(sub ? !less : less);
427  }
428 
429  if (less)
430  PG_RETURN_BOOL(val <= sum);
431  else
432  PG_RETURN_BOOL(val >= sum);
433 }
434 
435 
436 /*----------------------------------------------------------
437  * Arithmetic operators on 64-bit integers.
438  *---------------------------------------------------------*/
439 
440 Datum
442 {
443  int64 arg = PG_GETARG_INT64(0);
444  int64 result;
445 
446  if (unlikely(arg == PG_INT64_MIN))
447  ereport(ERROR,
448  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
449  errmsg("bigint out of range")));
450  result = -arg;
451  PG_RETURN_INT64(result);
452 }
453 
454 Datum
456 {
457  int64 arg = PG_GETARG_INT64(0);
458 
460 }
461 
462 Datum
464 {
465  int64 arg1 = PG_GETARG_INT64(0);
466  int64 arg2 = PG_GETARG_INT64(1);
467  int64 result;
468 
469  if (unlikely(pg_add_s64_overflow(arg1, arg2, &result)))
470  ereport(ERROR,
471  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
472  errmsg("bigint out of range")));
473  PG_RETURN_INT64(result);
474 }
475 
476 Datum
478 {
479  int64 arg1 = PG_GETARG_INT64(0);
480  int64 arg2 = PG_GETARG_INT64(1);
481  int64 result;
482 
483  if (unlikely(pg_sub_s64_overflow(arg1, arg2, &result)))
484  ereport(ERROR,
485  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
486  errmsg("bigint out of range")));
487  PG_RETURN_INT64(result);
488 }
489 
490 Datum
492 {
493  int64 arg1 = PG_GETARG_INT64(0);
494  int64 arg2 = PG_GETARG_INT64(1);
495  int64 result;
496 
497  if (unlikely(pg_mul_s64_overflow(arg1, arg2, &result)))
498  ereport(ERROR,
499  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
500  errmsg("bigint out of range")));
501  PG_RETURN_INT64(result);
502 }
503 
504 Datum
506 {
507  int64 arg1 = PG_GETARG_INT64(0);
508  int64 arg2 = PG_GETARG_INT64(1);
509  int64 result;
510 
511  if (arg2 == 0)
512  {
513  ereport(ERROR,
514  (errcode(ERRCODE_DIVISION_BY_ZERO),
515  errmsg("division by zero")));
516  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
517  PG_RETURN_NULL();
518  }
519 
520  /*
521  * INT64_MIN / -1 is problematic, since the result can't be represented on
522  * a two's-complement machine. Some machines produce INT64_MIN, some
523  * produce zero, some throw an exception. We can dodge the problem by
524  * recognizing that division by -1 is the same as negation.
525  */
526  if (arg2 == -1)
527  {
528  if (unlikely(arg1 == PG_INT64_MIN))
529  ereport(ERROR,
530  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
531  errmsg("bigint out of range")));
532  result = -arg1;
533  PG_RETURN_INT64(result);
534  }
535 
536  /* No overflow is possible */
537 
538  result = arg1 / arg2;
539 
540  PG_RETURN_INT64(result);
541 }
542 
543 /* int8abs()
544  * Absolute value
545  */
546 Datum
548 {
549  int64 arg1 = PG_GETARG_INT64(0);
550  int64 result;
551 
552  if (unlikely(arg1 == PG_INT64_MIN))
553  ereport(ERROR,
554  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
555  errmsg("bigint out of range")));
556  result = (arg1 < 0) ? -arg1 : arg1;
557  PG_RETURN_INT64(result);
558 }
559 
560 /* int8mod()
561  * Modulo operation.
562  */
563 Datum
565 {
566  int64 arg1 = PG_GETARG_INT64(0);
567  int64 arg2 = PG_GETARG_INT64(1);
568 
569  if (unlikely(arg2 == 0))
570  {
571  ereport(ERROR,
572  (errcode(ERRCODE_DIVISION_BY_ZERO),
573  errmsg("division by zero")));
574  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
575  PG_RETURN_NULL();
576  }
577 
578  /*
579  * Some machines throw a floating-point exception for INT64_MIN % -1,
580  * which is a bit silly since the correct answer is perfectly
581  * well-defined, namely zero.
582  */
583  if (arg2 == -1)
584  PG_RETURN_INT64(0);
585 
586  /* No overflow is possible */
587 
588  PG_RETURN_INT64(arg1 % arg2);
589 }
590 
591 /*
592  * Greatest Common Divisor
593  *
594  * Returns the largest positive integer that exactly divides both inputs.
595  * Special cases:
596  * - gcd(x, 0) = gcd(0, x) = abs(x)
597  * because 0 is divisible by anything
598  * - gcd(0, 0) = 0
599  * complies with the previous definition and is a common convention
600  *
601  * Special care must be taken if either input is INT64_MIN ---
602  * gcd(0, INT64_MIN), gcd(INT64_MIN, 0) and gcd(INT64_MIN, INT64_MIN) are
603  * all equal to abs(INT64_MIN), which cannot be represented as a 64-bit signed
604  * integer.
605  */
606 static int64
607 int8gcd_internal(int64 arg1, int64 arg2)
608 {
609  int64 swap;
610  int64 a1,
611  a2;
612 
613  /*
614  * Put the greater absolute value in arg1.
615  *
616  * This would happen automatically in the loop below, but avoids an
617  * expensive modulo operation, and simplifies the special-case handling
618  * for INT64_MIN below.
619  *
620  * We do this in negative space in order to handle INT64_MIN.
621  */
622  a1 = (arg1 < 0) ? arg1 : -arg1;
623  a2 = (arg2 < 0) ? arg2 : -arg2;
624  if (a1 > a2)
625  {
626  swap = arg1;
627  arg1 = arg2;
628  arg2 = swap;
629  }
630 
631  /* Special care needs to be taken with INT64_MIN. See comments above. */
632  if (arg1 == PG_INT64_MIN)
633  {
634  if (arg2 == 0 || arg2 == PG_INT64_MIN)
635  ereport(ERROR,
636  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
637  errmsg("bigint out of range")));
638 
639  /*
640  * Some machines throw a floating-point exception for INT64_MIN % -1,
641  * which is a bit silly since the correct answer is perfectly
642  * well-defined, namely zero. Guard against this and just return the
643  * result, gcd(INT64_MIN, -1) = 1.
644  */
645  if (arg2 == -1)
646  return 1;
647  }
648 
649  /* Use the Euclidean algorithm to find the GCD */
650  while (arg2 != 0)
651  {
652  swap = arg2;
653  arg2 = arg1 % arg2;
654  arg1 = swap;
655  }
656 
657  /*
658  * Make sure the result is positive. (We know we don't have INT64_MIN
659  * anymore).
660  */
661  if (arg1 < 0)
662  arg1 = -arg1;
663 
664  return arg1;
665 }
666 
667 Datum
669 {
670  int64 arg1 = PG_GETARG_INT64(0);
671  int64 arg2 = PG_GETARG_INT64(1);
672  int64 result;
673 
674  result = int8gcd_internal(arg1, arg2);
675 
676  PG_RETURN_INT64(result);
677 }
678 
679 /*
680  * Least Common Multiple
681  */
682 Datum
684 {
685  int64 arg1 = PG_GETARG_INT64(0);
686  int64 arg2 = PG_GETARG_INT64(1);
687  int64 gcd;
688  int64 result;
689 
690  /*
691  * Handle lcm(x, 0) = lcm(0, x) = 0 as a special case. This prevents a
692  * division-by-zero error below when x is zero, and an overflow error from
693  * the GCD computation when x = INT64_MIN.
694  */
695  if (arg1 == 0 || arg2 == 0)
696  PG_RETURN_INT64(0);
697 
698  /* lcm(x, y) = abs(x / gcd(x, y) * y) */
699  gcd = int8gcd_internal(arg1, arg2);
700  arg1 = arg1 / gcd;
701 
702  if (unlikely(pg_mul_s64_overflow(arg1, arg2, &result)))
703  ereport(ERROR,
704  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
705  errmsg("bigint out of range")));
706 
707  /* If the result is INT64_MIN, it cannot be represented. */
708  if (unlikely(result == PG_INT64_MIN))
709  ereport(ERROR,
710  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
711  errmsg("bigint out of range")));
712 
713  if (result < 0)
714  result = -result;
715 
716  PG_RETURN_INT64(result);
717 }
718 
719 Datum
721 {
722  /*
723  * When int8 is pass-by-reference, we provide this special case to avoid
724  * palloc overhead for COUNT(): when called as an aggregate, we know that
725  * the argument is modifiable local storage, so just update it in-place.
726  * (If int8 is pass-by-value, then of course this is useless as well as
727  * incorrect, so just ifdef it out.)
728  */
729 #ifndef USE_FLOAT8_BYVAL /* controls int8 too */
730  if (AggCheckCallContext(fcinfo, NULL))
731  {
732  int64 *arg = (int64 *) PG_GETARG_POINTER(0);
733 
734  if (unlikely(pg_add_s64_overflow(*arg, 1, arg)))
735  ereport(ERROR,
736  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
737  errmsg("bigint out of range")));
738 
740  }
741  else
742 #endif
743  {
744  /* Not called as an aggregate, so just do it the dumb way */
745  int64 arg = PG_GETARG_INT64(0);
746  int64 result;
747 
748  if (unlikely(pg_add_s64_overflow(arg, 1, &result)))
749  ereport(ERROR,
750  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
751  errmsg("bigint out of range")));
752 
753  PG_RETURN_INT64(result);
754  }
755 }
756 
757 Datum
759 {
760  /*
761  * When int8 is pass-by-reference, we provide this special case to avoid
762  * palloc overhead for COUNT(): when called as an aggregate, we know that
763  * the argument is modifiable local storage, so just update it in-place.
764  * (If int8 is pass-by-value, then of course this is useless as well as
765  * incorrect, so just ifdef it out.)
766  */
767 #ifndef USE_FLOAT8_BYVAL /* controls int8 too */
768  if (AggCheckCallContext(fcinfo, NULL))
769  {
770  int64 *arg = (int64 *) PG_GETARG_POINTER(0);
771 
772  if (unlikely(pg_sub_s64_overflow(*arg, 1, arg)))
773  ereport(ERROR,
774  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
775  errmsg("bigint out of range")));
777  }
778  else
779 #endif
780  {
781  /* Not called as an aggregate, so just do it the dumb way */
782  int64 arg = PG_GETARG_INT64(0);
783  int64 result;
784 
785  if (unlikely(pg_sub_s64_overflow(arg, 1, &result)))
786  ereport(ERROR,
787  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
788  errmsg("bigint out of range")));
789 
790  PG_RETURN_INT64(result);
791  }
792 }
793 
794 
795 /*
796  * These functions are exactly like int8inc/int8dec but are used for
797  * aggregates that count only non-null values. Since the functions are
798  * declared strict, the null checks happen before we ever get here, and all we
799  * need do is increment the state value. We could actually make these pg_proc
800  * entries point right at int8inc/int8dec, but then the opr_sanity regression
801  * test would complain about mismatched entries for a built-in function.
802  */
803 
804 Datum
806 {
807  return int8inc(fcinfo);
808 }
809 
810 Datum
812 {
813  return int8inc(fcinfo);
814 }
815 
816 Datum
818 {
819  return int8dec(fcinfo);
820 }
821 
822 /*
823  * int8inc_support
824  * prosupport function for int8inc() and int8inc_any()
825  */
826 Datum
828 {
829  Node *rawreq = (Node *) PG_GETARG_POINTER(0);
830 
831  if (IsA(rawreq, SupportRequestWFuncMonotonic))
832  {
835  int frameOptions = req->window_clause->frameOptions;
836 
837  /* No ORDER BY clause then all rows are peers */
838  if (req->window_clause->orderClause == NIL)
839  monotonic = MONOTONICFUNC_BOTH;
840  else
841  {
842  /*
843  * Otherwise take into account the frame options. When the frame
844  * bound is the start of the window then the resulting value can
845  * never decrease, therefore is monotonically increasing
846  */
847  if (frameOptions & FRAMEOPTION_START_UNBOUNDED_PRECEDING)
848  monotonic |= MONOTONICFUNC_INCREASING;
849 
850  /*
851  * Likewise, if the frame bound is the end of the window then the
852  * resulting value can never decrease.
853  */
854  if (frameOptions & FRAMEOPTION_END_UNBOUNDED_FOLLOWING)
855  monotonic |= MONOTONICFUNC_DECREASING;
856  }
857 
858  req->monotonic = monotonic;
859  PG_RETURN_POINTER(req);
860  }
861 
862  PG_RETURN_POINTER(NULL);
863 }
864 
865 
866 Datum
868 {
869  int64 arg1 = PG_GETARG_INT64(0);
870  int64 arg2 = PG_GETARG_INT64(1);
871  int64 result;
872 
873  result = ((arg1 > arg2) ? arg1 : arg2);
874 
875  PG_RETURN_INT64(result);
876 }
877 
878 Datum
880 {
881  int64 arg1 = PG_GETARG_INT64(0);
882  int64 arg2 = PG_GETARG_INT64(1);
883  int64 result;
884 
885  result = ((arg1 < arg2) ? arg1 : arg2);
886 
887  PG_RETURN_INT64(result);
888 }
889 
890 Datum
892 {
893  int64 arg1 = PG_GETARG_INT64(0);
894  int32 arg2 = PG_GETARG_INT32(1);
895  int64 result;
896 
897  if (unlikely(pg_add_s64_overflow(arg1, (int64) arg2, &result)))
898  ereport(ERROR,
899  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
900  errmsg("bigint out of range")));
901  PG_RETURN_INT64(result);
902 }
903 
904 Datum
906 {
907  int64 arg1 = PG_GETARG_INT64(0);
908  int32 arg2 = PG_GETARG_INT32(1);
909  int64 result;
910 
911  if (unlikely(pg_sub_s64_overflow(arg1, (int64) arg2, &result)))
912  ereport(ERROR,
913  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
914  errmsg("bigint out of range")));
915  PG_RETURN_INT64(result);
916 }
917 
918 Datum
920 {
921  int64 arg1 = PG_GETARG_INT64(0);
922  int32 arg2 = PG_GETARG_INT32(1);
923  int64 result;
924 
925  if (unlikely(pg_mul_s64_overflow(arg1, (int64) arg2, &result)))
926  ereport(ERROR,
927  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
928  errmsg("bigint out of range")));
929  PG_RETURN_INT64(result);
930 }
931 
932 Datum
934 {
935  int64 arg1 = PG_GETARG_INT64(0);
936  int32 arg2 = PG_GETARG_INT32(1);
937  int64 result;
938 
939  if (arg2 == 0)
940  {
941  ereport(ERROR,
942  (errcode(ERRCODE_DIVISION_BY_ZERO),
943  errmsg("division by zero")));
944  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
945  PG_RETURN_NULL();
946  }
947 
948  /*
949  * INT64_MIN / -1 is problematic, since the result can't be represented on
950  * a two's-complement machine. Some machines produce INT64_MIN, some
951  * produce zero, some throw an exception. We can dodge the problem by
952  * recognizing that division by -1 is the same as negation.
953  */
954  if (arg2 == -1)
955  {
956  if (unlikely(arg1 == PG_INT64_MIN))
957  ereport(ERROR,
958  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
959  errmsg("bigint out of range")));
960  result = -arg1;
961  PG_RETURN_INT64(result);
962  }
963 
964  /* No overflow is possible */
965 
966  result = arg1 / arg2;
967 
968  PG_RETURN_INT64(result);
969 }
970 
971 Datum
973 {
974  int32 arg1 = PG_GETARG_INT32(0);
975  int64 arg2 = PG_GETARG_INT64(1);
976  int64 result;
977 
978  if (unlikely(pg_add_s64_overflow((int64) arg1, arg2, &result)))
979  ereport(ERROR,
980  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
981  errmsg("bigint out of range")));
982  PG_RETURN_INT64(result);
983 }
984 
985 Datum
987 {
988  int32 arg1 = PG_GETARG_INT32(0);
989  int64 arg2 = PG_GETARG_INT64(1);
990  int64 result;
991 
992  if (unlikely(pg_sub_s64_overflow((int64) arg1, arg2, &result)))
993  ereport(ERROR,
994  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
995  errmsg("bigint out of range")));
996  PG_RETURN_INT64(result);
997 }
998 
999 Datum
1001 {
1002  int32 arg1 = PG_GETARG_INT32(0);
1003  int64 arg2 = PG_GETARG_INT64(1);
1004  int64 result;
1005 
1006  if (unlikely(pg_mul_s64_overflow((int64) arg1, arg2, &result)))
1007  ereport(ERROR,
1008  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1009  errmsg("bigint out of range")));
1010  PG_RETURN_INT64(result);
1011 }
1012 
1013 Datum
1015 {
1016  int32 arg1 = PG_GETARG_INT32(0);
1017  int64 arg2 = PG_GETARG_INT64(1);
1018 
1019  if (unlikely(arg2 == 0))
1020  {
1021  ereport(ERROR,
1022  (errcode(ERRCODE_DIVISION_BY_ZERO),
1023  errmsg("division by zero")));
1024  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1025  PG_RETURN_NULL();
1026  }
1027 
1028  /* No overflow is possible */
1029  PG_RETURN_INT64((int64) arg1 / arg2);
1030 }
1031 
1032 Datum
1034 {
1035  int64 arg1 = PG_GETARG_INT64(0);
1036  int16 arg2 = PG_GETARG_INT16(1);
1037  int64 result;
1038 
1039  if (unlikely(pg_add_s64_overflow(arg1, (int64) arg2, &result)))
1040  ereport(ERROR,
1041  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1042  errmsg("bigint out of range")));
1043  PG_RETURN_INT64(result);
1044 }
1045 
1046 Datum
1048 {
1049  int64 arg1 = PG_GETARG_INT64(0);
1050  int16 arg2 = PG_GETARG_INT16(1);
1051  int64 result;
1052 
1053  if (unlikely(pg_sub_s64_overflow(arg1, (int64) arg2, &result)))
1054  ereport(ERROR,
1055  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1056  errmsg("bigint out of range")));
1057  PG_RETURN_INT64(result);
1058 }
1059 
1060 Datum
1062 {
1063  int64 arg1 = PG_GETARG_INT64(0);
1064  int16 arg2 = PG_GETARG_INT16(1);
1065  int64 result;
1066 
1067  if (unlikely(pg_mul_s64_overflow(arg1, (int64) arg2, &result)))
1068  ereport(ERROR,
1069  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1070  errmsg("bigint out of range")));
1071  PG_RETURN_INT64(result);
1072 }
1073 
1074 Datum
1076 {
1077  int64 arg1 = PG_GETARG_INT64(0);
1078  int16 arg2 = PG_GETARG_INT16(1);
1079  int64 result;
1080 
1081  if (unlikely(arg2 == 0))
1082  {
1083  ereport(ERROR,
1084  (errcode(ERRCODE_DIVISION_BY_ZERO),
1085  errmsg("division by zero")));
1086  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1087  PG_RETURN_NULL();
1088  }
1089 
1090  /*
1091  * INT64_MIN / -1 is problematic, since the result can't be represented on
1092  * a two's-complement machine. Some machines produce INT64_MIN, some
1093  * produce zero, some throw an exception. We can dodge the problem by
1094  * recognizing that division by -1 is the same as negation.
1095  */
1096  if (arg2 == -1)
1097  {
1098  if (unlikely(arg1 == PG_INT64_MIN))
1099  ereport(ERROR,
1100  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1101  errmsg("bigint out of range")));
1102  result = -arg1;
1103  PG_RETURN_INT64(result);
1104  }
1105 
1106  /* No overflow is possible */
1107 
1108  result = arg1 / arg2;
1109 
1110  PG_RETURN_INT64(result);
1111 }
1112 
1113 Datum
1115 {
1116  int16 arg1 = PG_GETARG_INT16(0);
1117  int64 arg2 = PG_GETARG_INT64(1);
1118  int64 result;
1119 
1120  if (unlikely(pg_add_s64_overflow((int64) arg1, arg2, &result)))
1121  ereport(ERROR,
1122  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1123  errmsg("bigint out of range")));
1124  PG_RETURN_INT64(result);
1125 }
1126 
1127 Datum
1129 {
1130  int16 arg1 = PG_GETARG_INT16(0);
1131  int64 arg2 = PG_GETARG_INT64(1);
1132  int64 result;
1133 
1134  if (unlikely(pg_sub_s64_overflow((int64) arg1, arg2, &result)))
1135  ereport(ERROR,
1136  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1137  errmsg("bigint out of range")));
1138  PG_RETURN_INT64(result);
1139 }
1140 
1141 Datum
1143 {
1144  int16 arg1 = PG_GETARG_INT16(0);
1145  int64 arg2 = PG_GETARG_INT64(1);
1146  int64 result;
1147 
1148  if (unlikely(pg_mul_s64_overflow((int64) arg1, arg2, &result)))
1149  ereport(ERROR,
1150  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1151  errmsg("bigint out of range")));
1152  PG_RETURN_INT64(result);
1153 }
1154 
1155 Datum
1157 {
1158  int16 arg1 = PG_GETARG_INT16(0);
1159  int64 arg2 = PG_GETARG_INT64(1);
1160 
1161  if (unlikely(arg2 == 0))
1162  {
1163  ereport(ERROR,
1164  (errcode(ERRCODE_DIVISION_BY_ZERO),
1165  errmsg("division by zero")));
1166  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1167  PG_RETURN_NULL();
1168  }
1169 
1170  /* No overflow is possible */
1171  PG_RETURN_INT64((int64) arg1 / arg2);
1172 }
1173 
1174 /* Binary arithmetics
1175  *
1176  * int8and - returns arg1 & arg2
1177  * int8or - returns arg1 | arg2
1178  * int8xor - returns arg1 # arg2
1179  * int8not - returns ~arg1
1180  * int8shl - returns arg1 << arg2
1181  * int8shr - returns arg1 >> arg2
1182  */
1183 
1184 Datum
1186 {
1187  int64 arg1 = PG_GETARG_INT64(0);
1188  int64 arg2 = PG_GETARG_INT64(1);
1189 
1190  PG_RETURN_INT64(arg1 & arg2);
1191 }
1192 
1193 Datum
1195 {
1196  int64 arg1 = PG_GETARG_INT64(0);
1197  int64 arg2 = PG_GETARG_INT64(1);
1198 
1199  PG_RETURN_INT64(arg1 | arg2);
1200 }
1201 
1202 Datum
1204 {
1205  int64 arg1 = PG_GETARG_INT64(0);
1206  int64 arg2 = PG_GETARG_INT64(1);
1207 
1208  PG_RETURN_INT64(arg1 ^ arg2);
1209 }
1210 
1211 Datum
1213 {
1214  int64 arg1 = PG_GETARG_INT64(0);
1215 
1216  PG_RETURN_INT64(~arg1);
1217 }
1218 
1219 Datum
1221 {
1222  int64 arg1 = PG_GETARG_INT64(0);
1223  int32 arg2 = PG_GETARG_INT32(1);
1224 
1225  PG_RETURN_INT64(arg1 << arg2);
1226 }
1227 
1228 Datum
1230 {
1231  int64 arg1 = PG_GETARG_INT64(0);
1232  int32 arg2 = PG_GETARG_INT32(1);
1233 
1234  PG_RETURN_INT64(arg1 >> arg2);
1235 }
1236 
1237 /*----------------------------------------------------------
1238  * Conversion operators.
1239  *---------------------------------------------------------*/
1240 
1241 Datum
1243 {
1244  int32 arg = PG_GETARG_INT32(0);
1245 
1246  PG_RETURN_INT64((int64) arg);
1247 }
1248 
1249 Datum
1251 {
1252  int64 arg = PG_GETARG_INT64(0);
1253 
1255  ereport(ERROR,
1256  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1257  errmsg("integer out of range")));
1258 
1260 }
1261 
1262 Datum
1264 {
1265  int16 arg = PG_GETARG_INT16(0);
1266 
1267  PG_RETURN_INT64((int64) arg);
1268 }
1269 
1270 Datum
1272 {
1273  int64 arg = PG_GETARG_INT64(0);
1274 
1276  ereport(ERROR,
1277  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1278  errmsg("smallint out of range")));
1279 
1281 }
1282 
1283 Datum
1285 {
1286  int64 arg = PG_GETARG_INT64(0);
1287  float8 result;
1288 
1289  result = arg;
1290 
1291  PG_RETURN_FLOAT8(result);
1292 }
1293 
1294 /* dtoi8()
1295  * Convert float8 to 8-byte integer.
1296  */
1297 Datum
1299 {
1300  float8 num = PG_GETARG_FLOAT8(0);
1301 
1302  /*
1303  * Get rid of any fractional part in the input. This is so we don't fail
1304  * on just-out-of-range values that would round into range. Note
1305  * assumption that rint() will pass through a NaN or Inf unchanged.
1306  */
1307  num = rint(num);
1308 
1309  /* Range check */
1310  if (unlikely(isnan(num) || !FLOAT8_FITS_IN_INT64(num)))
1311  ereport(ERROR,
1312  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1313  errmsg("bigint out of range")));
1314 
1315  PG_RETURN_INT64((int64) num);
1316 }
1317 
1318 Datum
1320 {
1321  int64 arg = PG_GETARG_INT64(0);
1322  float4 result;
1323 
1324  result = arg;
1325 
1326  PG_RETURN_FLOAT4(result);
1327 }
1328 
1329 /* ftoi8()
1330  * Convert float4 to 8-byte integer.
1331  */
1332 Datum
1334 {
1335  float4 num = PG_GETARG_FLOAT4(0);
1336 
1337  /*
1338  * Get rid of any fractional part in the input. This is so we don't fail
1339  * on just-out-of-range values that would round into range. Note
1340  * assumption that rint() will pass through a NaN or Inf unchanged.
1341  */
1342  num = rint(num);
1343 
1344  /* Range check */
1345  if (unlikely(isnan(num) || !FLOAT4_FITS_IN_INT64(num)))
1346  ereport(ERROR,
1347  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1348  errmsg("bigint out of range")));
1349 
1350  PG_RETURN_INT64((int64) num);
1351 }
1352 
1353 Datum
1355 {
1356  int64 arg = PG_GETARG_INT64(0);
1357 
1358  if (unlikely(arg < 0) || unlikely(arg > PG_UINT32_MAX))
1359  ereport(ERROR,
1360  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1361  errmsg("OID out of range")));
1362 
1363  PG_RETURN_OID((Oid) arg);
1364 }
1365 
1366 Datum
1368 {
1369  Oid arg = PG_GETARG_OID(0);
1370 
1371  PG_RETURN_INT64((int64) arg);
1372 }
1373 
1374 /*
1375  * non-persistent numeric series generator
1376  */
1377 Datum
1379 {
1380  return generate_series_step_int8(fcinfo);
1381 }
1382 
1383 Datum
1385 {
1386  FuncCallContext *funcctx;
1387  generate_series_fctx *fctx;
1388  int64 result;
1389  MemoryContext oldcontext;
1390 
1391  /* stuff done only on the first call of the function */
1392  if (SRF_IS_FIRSTCALL())
1393  {
1394  int64 start = PG_GETARG_INT64(0);
1395  int64 finish = PG_GETARG_INT64(1);
1396  int64 step = 1;
1397 
1398  /* see if we were given an explicit step size */
1399  if (PG_NARGS() == 3)
1400  step = PG_GETARG_INT64(2);
1401  if (step == 0)
1402  ereport(ERROR,
1403  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1404  errmsg("step size cannot equal zero")));
1405 
1406  /* create a function context for cross-call persistence */
1407  funcctx = SRF_FIRSTCALL_INIT();
1408 
1409  /*
1410  * switch to memory context appropriate for multiple function calls
1411  */
1412  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
1413 
1414  /* allocate memory for user context */
1415  fctx = (generate_series_fctx *) palloc(sizeof(generate_series_fctx));
1416 
1417  /*
1418  * Use fctx to keep state from call to call. Seed current with the
1419  * original start value
1420  */
1421  fctx->current = start;
1422  fctx->finish = finish;
1423  fctx->step = step;
1424 
1425  funcctx->user_fctx = fctx;
1426  MemoryContextSwitchTo(oldcontext);
1427  }
1428 
1429  /* stuff done on every call of the function */
1430  funcctx = SRF_PERCALL_SETUP();
1431 
1432  /*
1433  * get the saved state and use current as the result for this iteration
1434  */
1435  fctx = funcctx->user_fctx;
1436  result = fctx->current;
1437 
1438  if ((fctx->step > 0 && fctx->current <= fctx->finish) ||
1439  (fctx->step < 0 && fctx->current >= fctx->finish))
1440  {
1441  /*
1442  * Increment current in preparation for next iteration. If next-value
1443  * computation overflows, this is the final result.
1444  */
1445  if (pg_add_s64_overflow(fctx->current, fctx->step, &fctx->current))
1446  fctx->step = 0;
1447 
1448  /* do when there is more left to send */
1449  SRF_RETURN_NEXT(funcctx, Int64GetDatum(result));
1450  }
1451  else
1452  /* do when there is no more left */
1453  SRF_RETURN_DONE(funcctx);
1454 }
1455 
1456 /*
1457  * Planner support function for generate_series(int8, int8 [, int8])
1458  */
1459 Datum
1461 {
1462  Node *rawreq = (Node *) PG_GETARG_POINTER(0);
1463  Node *ret = NULL;
1464 
1465  if (IsA(rawreq, SupportRequestRows))
1466  {
1467  /* Try to estimate the number of rows returned */
1468  SupportRequestRows *req = (SupportRequestRows *) rawreq;
1469 
1470  if (is_funcclause(req->node)) /* be paranoid */
1471  {
1472  List *args = ((FuncExpr *) req->node)->args;
1473  Node *arg1,
1474  *arg2,
1475  *arg3;
1476 
1477  /* We can use estimated argument values here */
1479  arg2 = estimate_expression_value(req->root, lsecond(args));
1480  if (list_length(args) >= 3)
1481  arg3 = estimate_expression_value(req->root, lthird(args));
1482  else
1483  arg3 = NULL;
1484 
1485  /*
1486  * If any argument is constant NULL, we can safely assume that
1487  * zero rows are returned. Otherwise, if they're all non-NULL
1488  * constants, we can calculate the number of rows that will be
1489  * returned. Use double arithmetic to avoid overflow hazards.
1490  */
1491  if ((IsA(arg1, Const) &&
1492  ((Const *) arg1)->constisnull) ||
1493  (IsA(arg2, Const) &&
1494  ((Const *) arg2)->constisnull) ||
1495  (arg3 != NULL && IsA(arg3, Const) &&
1496  ((Const *) arg3)->constisnull))
1497  {
1498  req->rows = 0;
1499  ret = (Node *) req;
1500  }
1501  else if (IsA(arg1, Const) &&
1502  IsA(arg2, Const) &&
1503  (arg3 == NULL || IsA(arg3, Const)))
1504  {
1505  double start,
1506  finish,
1507  step;
1508 
1509  start = DatumGetInt64(((Const *) arg1)->constvalue);
1510  finish = DatumGetInt64(((Const *) arg2)->constvalue);
1511  step = arg3 ? DatumGetInt64(((Const *) arg3)->constvalue) : 1;
1512 
1513  /* This equation works for either sign of step */
1514  if (step != 0)
1515  {
1516  req->rows = floor((finish - start + step) / step);
1517  ret = (Node *) req;
1518  }
1519  }
1520  }
1521  }
1522 
1523  PG_RETURN_POINTER(ret);
1524 }
#define MAXINT8LEN
Definition: builtins.h:22
#define PG_INT32_MAX
Definition: c.h:524
signed short int16
Definition: c.h:428
#define PG_UINT32_MAX
Definition: c.h:525
#define FLOAT4_FITS_IN_INT64(num)
Definition: c.h:1098
signed int int32
Definition: c.h:429
double float8
Definition: c.h:565
#define FLOAT8_FITS_IN_INT64(num)
Definition: c.h:1104
#define PG_INT16_MIN
Definition: c.h:520
#define PG_INT64_MIN
Definition: c.h:526
#define unlikely(x)
Definition: c.h:273
float float4
Definition: c.h:564
#define PG_INT32_MIN
Definition: c.h:523
#define PG_INT16_MAX
Definition: c.h:521
Node * estimate_expression_value(PlannerInfo *root, Node *node)
Definition: clauses.c:2290
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define ERROR
Definition: elog.h:33
#define ereport(elevel,...)
Definition: elog.h:143
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1683
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:371
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362
#define PG_RETURN_INT64(x)
Definition: fmgr.h:368
#define PG_NARGS()
Definition: fmgr.h:203
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
#define PG_RETURN_NULL()
Definition: fmgr.h:345
#define PG_GETARG_INT64(n)
Definition: fmgr.h:283
#define PG_RETURN_INT16(x)
Definition: fmgr.h:356
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:366
#define PG_RETURN_OID(x)
Definition: fmgr.h:360
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:299
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:303
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:305
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:301
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:323
static const FormData_pg_attribute a1
Definition: heap.c:141
static const FormData_pg_attribute a2
Definition: heap.c:155
long val
Definition: informix.c:664
Datum int8lcm(PG_FUNCTION_ARGS)
Definition: int8.c:683
Datum int84div(PG_FUNCTION_ARGS)
Definition: int8.c:933
Datum int8ge(PG_FUNCTION_ARGS)
Definition: int8.c:159
Datum i8tooid(PG_FUNCTION_ARGS)
Definition: int8.c:1354
Datum int8dec_any(PG_FUNCTION_ARGS)
Definition: int8.c:817
Datum in_range_int8_int8(PG_FUNCTION_ARGS)
Definition: int8.c:402
Datum int8abs(PG_FUNCTION_ARGS)
Definition: int8.c:547
Datum int48ge(PG_FUNCTION_ARGS)
Definition: int8.c:273
Datum int82le(PG_FUNCTION_ARGS)
Definition: int8.c:321
Datum int28lt(PG_FUNCTION_ARGS)
Definition: int8.c:360
Datum int84pl(PG_FUNCTION_ARGS)
Definition: int8.c:891
Datum int48pl(PG_FUNCTION_ARGS)
Definition: int8.c:972
Datum int8out(PG_FUNCTION_ARGS)
Definition: int8.c:62
Datum int82mi(PG_FUNCTION_ARGS)
Definition: int8.c:1047
Datum int84gt(PG_FUNCTION_ARGS)
Definition: int8.c:198
Datum int28ne(PG_FUNCTION_ARGS)
Definition: int8.c:351
Datum int8send(PG_FUNCTION_ARGS)
Definition: int8.c:95
Datum int8ne(PG_FUNCTION_ARGS)
Definition: int8.c:123
Datum int84(PG_FUNCTION_ARGS)
Definition: int8.c:1250
Datum int8mul(PG_FUNCTION_ARGS)
Definition: int8.c:491
Datum int84ge(PG_FUNCTION_ARGS)
Definition: int8.c:216
Datum int48lt(PG_FUNCTION_ARGS)
Definition: int8.c:246
Datum int8gcd(PG_FUNCTION_ARGS)
Definition: int8.c:668
Datum int8not(PG_FUNCTION_ARGS)
Definition: int8.c:1212
Datum int8le(PG_FUNCTION_ARGS)
Definition: int8.c:150
Datum int8lt(PG_FUNCTION_ARGS)
Definition: int8.c:132
Datum int48eq(PG_FUNCTION_ARGS)
Definition: int8.c:228
Datum generate_series_step_int8(PG_FUNCTION_ARGS)
Definition: int8.c:1384
Datum generate_series_int8(PG_FUNCTION_ARGS)
Definition: int8.c:1378
Datum int8eq(PG_FUNCTION_ARGS)
Definition: int8.c:114
Datum generate_series_int8_support(PG_FUNCTION_ARGS)
Definition: int8.c:1460
Datum int82div(PG_FUNCTION_ARGS)
Definition: int8.c:1075
Datum int48le(PG_FUNCTION_ARGS)
Definition: int8.c:264
Datum int28gt(PG_FUNCTION_ARGS)
Definition: int8.c:369
Datum i8tod(PG_FUNCTION_ARGS)
Definition: int8.c:1284
Datum int8inc_support(PG_FUNCTION_ARGS)
Definition: int8.c:827
Datum int8in(PG_FUNCTION_ARGS)
Definition: int8.c:51
Datum int8mod(PG_FUNCTION_ARGS)
Definition: int8.c:564
Datum oidtoi8(PG_FUNCTION_ARGS)
Definition: int8.c:1367
Datum int28pl(PG_FUNCTION_ARGS)
Definition: int8.c:1114
Datum int84eq(PG_FUNCTION_ARGS)
Definition: int8.c:171
Datum int28div(PG_FUNCTION_ARGS)
Definition: int8.c:1156
Datum int8pl(PG_FUNCTION_ARGS)
Definition: int8.c:463
Datum int8larger(PG_FUNCTION_ARGS)
Definition: int8.c:867
Datum int8xor(PG_FUNCTION_ARGS)
Definition: int8.c:1203
Datum int28(PG_FUNCTION_ARGS)
Definition: int8.c:1263
Datum int8gt(PG_FUNCTION_ARGS)
Definition: int8.c:141
Datum int8div(PG_FUNCTION_ARGS)
Definition: int8.c:505
Datum int48ne(PG_FUNCTION_ARGS)
Definition: int8.c:237
Datum int82pl(PG_FUNCTION_ARGS)
Definition: int8.c:1033
Datum int48mul(PG_FUNCTION_ARGS)
Definition: int8.c:1000
Datum int48mi(PG_FUNCTION_ARGS)
Definition: int8.c:986
Datum int8up(PG_FUNCTION_ARGS)
Definition: int8.c:455
Datum int8smaller(PG_FUNCTION_ARGS)
Definition: int8.c:879
Datum int28le(PG_FUNCTION_ARGS)
Definition: int8.c:378
static int64 int8gcd_internal(int64 arg1, int64 arg2)
Definition: int8.c:607
Datum int82lt(PG_FUNCTION_ARGS)
Definition: int8.c:303
Datum int82gt(PG_FUNCTION_ARGS)
Definition: int8.c:312
Datum int82mul(PG_FUNCTION_ARGS)
Definition: int8.c:1061
Datum dtoi8(PG_FUNCTION_ARGS)
Definition: int8.c:1298
Datum int82ge(PG_FUNCTION_ARGS)
Definition: int8.c:330
Datum int48div(PG_FUNCTION_ARGS)
Definition: int8.c:1014
Datum int8inc_any(PG_FUNCTION_ARGS)
Definition: int8.c:805
Datum int48gt(PG_FUNCTION_ARGS)
Definition: int8.c:255
Datum int8or(PG_FUNCTION_ARGS)
Definition: int8.c:1194
Datum int48(PG_FUNCTION_ARGS)
Definition: int8.c:1242
Datum int8shr(PG_FUNCTION_ARGS)
Definition: int8.c:1229
Datum int8recv(PG_FUNCTION_ARGS)
Definition: int8.c:84
Datum int84le(PG_FUNCTION_ARGS)
Definition: int8.c:207
Datum int8dec(PG_FUNCTION_ARGS)
Definition: int8.c:758
Datum int84mi(PG_FUNCTION_ARGS)
Definition: int8.c:905
Datum int82ne(PG_FUNCTION_ARGS)
Definition: int8.c:294
Datum int82(PG_FUNCTION_ARGS)
Definition: int8.c:1271
Datum int8inc_float8_float8(PG_FUNCTION_ARGS)
Definition: int8.c:811
Datum int28ge(PG_FUNCTION_ARGS)
Definition: int8.c:387
Datum int8shl(PG_FUNCTION_ARGS)
Definition: int8.c:1220
Datum i8tof(PG_FUNCTION_ARGS)
Definition: int8.c:1319
Datum int82eq(PG_FUNCTION_ARGS)
Definition: int8.c:285
Datum int84ne(PG_FUNCTION_ARGS)
Definition: int8.c:180
Datum int8mi(PG_FUNCTION_ARGS)
Definition: int8.c:477
Datum ftoi8(PG_FUNCTION_ARGS)
Definition: int8.c:1333
Datum int8and(PG_FUNCTION_ARGS)
Definition: int8.c:1185
Datum int84mul(PG_FUNCTION_ARGS)
Definition: int8.c:919
Datum int8um(PG_FUNCTION_ARGS)
Definition: int8.c:441
Datum int28mi(PG_FUNCTION_ARGS)
Definition: int8.c:1128
Datum int84lt(PG_FUNCTION_ARGS)
Definition: int8.c:189
Datum int28eq(PG_FUNCTION_ARGS)
Definition: int8.c:342
Datum int28mul(PG_FUNCTION_ARGS)
Definition: int8.c:1142
Datum int8inc(PG_FUNCTION_ARGS)
Definition: int8.c:720
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:215
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:188
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:161
void * palloc(Size size)
Definition: mcxt.c:1068
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:4487
static bool is_funcclause(const void *clause)
Definition: nodeFuncs.h:57
#define IsA(nodeptr, _type_)
Definition: nodes.h:624
int64 pg_strtoint64(const char *s)
Definition: numutils.c:251
int pg_lltoa(int64 value, char *a)
Definition: numutils.c:519
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define FRAMEOPTION_START_UNBOUNDED_PRECEDING
Definition: parsenodes.h:540
#define FRAMEOPTION_END_UNBOUNDED_FOLLOWING
Definition: parsenodes.h:543
void * arg
const void size_t len
static int list_length(const List *l)
Definition: pg_list.h:149
#define NIL
Definition: pg_list.h:65
#define lthird(l)
Definition: pg_list.h:184
#define linitial(l)
Definition: pg_list.h:174
#define lsecond(l)
Definition: pg_list.h:179
static char * buf
Definition: pg_test_fsync.c:67
MonotonicFunction
Definition: plannodes.h:1342
@ MONOTONICFUNC_NONE
Definition: plannodes.h:1343
@ MONOTONICFUNC_DECREASING
Definition: plannodes.h:1345
@ MONOTONICFUNC_INCREASING
Definition: plannodes.h:1344
@ MONOTONICFUNC_BOTH
Definition: plannodes.h:1346
uintptr_t Datum
Definition: postgres.h:411
#define DatumGetInt64(X)
Definition: postgres.h:651
unsigned int Oid
Definition: postgres_ext.h:31
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:455
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
static void pq_sendint64(StringInfo buf, uint64 i)
Definition: pqformat.h:153
StringInfoData * StringInfo
Definition: stringinfo.h:44
void * user_fctx
Definition: funcapi.h:82
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:101
Definition: pg_list.h:51
Definition: nodes.h:574
struct PlannerInfo * root
Definition: supportnodes.h:163
struct WindowClause * window_clause
Definition: supportnodes.h:296
MonotonicFunction monotonic
Definition: supportnodes.h:299
List * orderClause
Definition: parsenodes.h:1402
int32 current
Definition: int.c:49
int32 finish
Definition: int.c:50
static uint32 gcd(uint32 a, uint32 b)