agora inbox for [email protected]help / color / mirror / Atom feed
[PATCH 1/8] introduce bsearch_arg 97+ messages / 2 participants [nested] [flat]
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210311.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------AC3FFB734F56C5F52D422EFC Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210305.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 2 +- 6 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 49614106dc..20221c1ae3 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -101,7 +101,7 @@ sub mkvcbuild dirent.c dlopen.c getopt.c getopt_long.c link.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c - pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c + pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c thread.c win32env.c win32error.c win32security.c win32setlocale.c win32stat.c); -- 2.26.2 --------------556A1DC61262AF15641DB204 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-func-20210308b.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* [PATCH 1/8] introduce bsearch_arg @ 2021-03-04 23:16 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Tomas Vondra @ 2021-03-04 23:16 UTC (permalink / raw) --- src/backend/statistics/extended_stats.c | 31 -------------- src/include/port.h | 5 +++ .../statistics/extended_stats_internal.h | 5 --- src/port/Makefile | 1 + src/port/bsearch_arg.c | 40 +++++++++++++++++++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 src/port/bsearch_arg.c diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index a030ea3653..fa42851fd5 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -659,37 +659,6 @@ compare_datums_simple(Datum a, Datum b, SortSupport ssup) return ApplySortComparator(a, false, b, false, ssup); } -/* simple counterpart to qsort_arg */ -void * -bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg) -{ - size_t l, - u, - idx; - const void *p; - int comparison; - - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p, arg); - - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; - } - - return NULL; -} - /* * build_attnums_array * Transforms a bitmap into an array of AttrNumber values. diff --git a/src/include/port.h b/src/include/port.h index 227ef4b148..82f63de325 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -508,6 +508,11 @@ typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg); extern void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg); +extern void *bsearch_arg(const void *key, const void *base, + size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg); + /* port/chklocale.c */ extern int pg_get_encoding_from_locale(const char *ctype, bool write_message); diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index c849bd57c0..a0a3cf5b0f 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -85,11 +85,6 @@ extern int multi_sort_compare_dims(int start, int end, const SortItem *a, extern int compare_scalars_simple(const void *a, const void *b, void *arg); extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup); -extern void *bsearch_arg(const void *key, const void *base, - size_t nmemb, size_t size, - int (*compar) (const void *, const void *, void *), - void *arg); - extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs); extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, diff --git a/src/port/Makefile b/src/port/Makefile index e41b005c4f..52dbf5783f 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -40,6 +40,7 @@ LIBS += $(PTHREAD_LIBS) OBJS = \ $(LIBOBJS) \ $(PG_CRC32C_OBJS) \ + bsearch_arg.o \ chklocale.o \ erand48.o \ inet_net_ntop.o \ diff --git a/src/port/bsearch_arg.c b/src/port/bsearch_arg.c new file mode 100644 index 0000000000..d24dc4b7c4 --- /dev/null +++ b/src/port/bsearch_arg.c @@ -0,0 +1,40 @@ +/* + * bsearch_arg.c: bsearch variant with a user-supplied pointer + * + * src/port/bsearch_arg.c + */ + + +#include "c.h" + + +/* simple counterpart to qsort_arg */ +void * +bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *, void *), + void *arg) +{ + size_t l, + u, + idx; + const void *p; + int comparison; + + l = 0; + u = nmemb; + while (l < u) + { + idx = (l + u) / 2; + p = (void *) (((const char *) base) + (idx * size)); + comparison = (*compar) (key, p, arg); + + if (comparison < 0) + u = idx; + else if (comparison > 0) + l = idx + 1; + else + return (void *) p; + } + + return NULL; +} -- 2.26.2 --------------82D677E9F94AC7574E460205 Content-Type: text/x-patch; charset=UTF-8; name="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-Pass-all-scan-keys-to-BRIN-consistent-funct-20210308.pa"; filename*1="tch" ^ permalink raw reply [nested|flat] 97+ messages in thread
* Re: deparsing utility commands @ 2022-04-15 16:40 Ajin Cherian <[email protected]> 0 siblings, 0 replies; 97+ messages in thread From: Ajin Cherian @ 2022-04-15 16:40 UTC (permalink / raw) To: Shulgin, Oleksandr <[email protected]>; +Cc: Alvaro Herrera <[email protected]>; David Steele <[email protected]>; Amit Kapila <[email protected]>; pgsql-hackers On Wed, Apr 13, 2022 at 2:12 PM Shulgin, Oleksandr <[email protected]> wrote: > > >> You seem to have squashed the patches? Please keep the split out. > > > Well, if that makes the review process easier :-) > > -- > Alex > I've rebased patches 1, 2 and 5 (now 1,2 and 3). Patches 3 and 4 seem to be related to the testing of the extension and contrib module ddl_deparse which is not in this patch-set, so I have left those patches out, as I have no way of testing the test cases added as part of these patches. regards, Ajin Cherian Fujitsu Australia Attachments: [application/octet-stream] 0002-Move-some-ddl-deparsing-code-from-ruleutils-to-exten.patch (17.4K, ../../CAFPTHDaCp7-FRjkYnfjsBTUxrRX9P9f6t8TEhR1CZVoKHCwbTQ@mail.gmail.com/2-0002-Move-some-ddl-deparsing-code-from-ruleutils-to-exten.patch) download | inline diff: From d471ba92638dbf59a53a3a9e8a68dbce2db70692 Mon Sep 17 00:00:00 2001 From: Ajin Cherian <[email protected]> Date: Wed, 13 Apr 2022 09:13:28 -0400 Subject: [PATCH 2/3] Move some ddl-deparsing code from ruleutils to extension. --- src/backend/utils/adt/format_type.c | 125 -------------- src/backend/utils/adt/ruleutils.c | 325 +----------------------------------- src/include/utils/builtins.h | 4 - src/include/utils/ruleutils.h | 17 +- 4 files changed, 8 insertions(+), 463 deletions(-) diff --git a/src/backend/utils/adt/format_type.c b/src/backend/utils/adt/format_type.c index 42e3af3..060fd7e 100644 --- a/src/backend/utils/adt/format_type.c +++ b/src/backend/utils/adt/format_type.c @@ -334,131 +334,6 @@ format_type_extended(Oid type_oid, int32 typemod, bits16 flags) } /* - * Similar to format_type_internal, except we return each bit of information - * separately: - * - * - nspid is the schema OID. For certain SQL-standard types which have weird - * typmod rules, we return InvalidOid; caller is expected to not schema- - * qualify the name nor add quotes to the type name in this case. - * - * - typename is set to the type name, without quotes - * - * - typmod is set to the typemod, if any, as a string with parens - * - * - typarray indicates whether []s must be added - * - * We don't try to decode type names to their standard-mandated names, except - * in the cases of types with unusual typmod rules. - */ -void -format_type_detailed(Oid type_oid, int32 typemod, - Oid *nspid, char **typname, char **typemodstr, - bool *typarray) -{ - HeapTuple tuple; - Form_pg_type typeform; - Oid array_base_type; - - tuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(type_oid)); - if (!HeapTupleIsValid(tuple)) - elog(ERROR, "cache lookup failed for type %u", type_oid); - - typeform = (Form_pg_type) GETSTRUCT(tuple); - - /* * Special-case crock for types with strange typmod rules. - */ - if (type_oid == INTERVALOID || - type_oid == TIMESTAMPOID || - type_oid == TIMESTAMPTZOID || - type_oid == TIMEOID || - type_oid == TIMETZOID) - { - *typarray = false; - -peculiar_typmod: - switch (type_oid) - { - case INTERVALOID: - *typname = pstrdup("INTERVAL"); - break; - case TIMESTAMPTZOID: - if (typemod < 0) - { - *typname = pstrdup("TIMESTAMP WITH TIME ZONE"); - break; - } - /* otherwise, WITH TZ is added by typmod, so fall through */ - case TIMESTAMPOID: - *typname = pstrdup("TIMESTAMP"); - break; - case TIMETZOID: - if (typemod < 0) - { - *typname = pstrdup("TIME WITH TIME ZONE"); - break; - } - /* otherwise, WITH TZ is added by typmode, so fall through */ - case TIMEOID: - *typname = pstrdup("TIME"); - break; - } - *nspid = InvalidOid; - - if (typemod >= 0) - *typemodstr = printTypmod(NULL, typemod, typeform->typmodout); - else - *typemodstr = pstrdup(""); - - ReleaseSysCache(tuple); - return; - } - - /* - * Check if it's a regular (variable length) array type. As above, - * fixed-length array types such as "name" shouldn't get deconstructed. - */ - array_base_type = typeform->typelem; - - if (array_base_type != InvalidOid && - typeform->typstorage != 'p') - { - /* Switch our attention to the array element type */ - ReleaseSysCache(tuple); - tuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(array_base_type)); - if (!HeapTupleIsValid(tuple)) - elog(ERROR, "cache lookup failed for type %u", type_oid); - - typeform = (Form_pg_type) GETSTRUCT(tuple); - type_oid = array_base_type; - *typarray = true; - - /* - * If it's an array of one of the types with special typmod rules, - * have the element type be processed as above, but now with typarray - * set to true. - */ - if (type_oid == INTERVALOID || - type_oid == TIMESTAMPTZOID || - type_oid == TIMESTAMPOID || - type_oid == TIMETZOID || - type_oid == TIMEOID) - goto peculiar_typmod; - } - else - *typarray = false; - - *nspid = typeform->typnamespace; - *typname = pstrdup(NameStr(typeform->typname)); - - if (typemod >= 0) - *typemodstr = printTypmod(NULL, typemod, typeform->typmodout); - else - *typemodstr = pstrdup(""); - - ReleaseSysCache(tuple); -} - -/* * This version is for use within the backend in error messages, etc. * One difference is that it will fail for an invalid type. * diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index f1d6e9a..77a5b79 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -484,8 +484,6 @@ static void get_from_clause_coldeflist(RangeTblFunction *rtfunc, deparse_context *context); static void get_tablesample_def(TableSampleClause *tablesample, deparse_context *context); -static void get_opclass_name(Oid opclass, Oid actual_datatype, - StringInfo buf); static Node *processIndirection(Node *node, deparse_context *context); static void printSubscripts(SubscriptingRef *sbsref, deparse_context *context); static char *get_relation_name(Oid relid); @@ -499,7 +497,6 @@ static char *generate_operator_name(Oid operid, Oid arg1, Oid arg2); static void add_cast_to(StringInfo buf, Oid typid); static char *generate_qualified_type_name(Oid typid); static text *string_to_text(char *str); -static char *flatten_reloptions(Oid relid); static void get_reloptions(StringInfo buf, Datum reloptions); static void get_json_path_spec(Node *path_spec, deparse_context *context, bool showimplicit); @@ -558,8 +555,8 @@ pg_get_ruledef_ext(PG_FUNCTION_ARGS) * NIL, signalling NOTHING) in actions. */ void -pg_get_ruledef_details(Datum ev_qual, Datum ev_action, - char **whereClause, List **actions) +pg_get_ruledef_detailed(Datum ev_qual, Datum ev_action, + char **whereClause, List **actions) { int prettyFlags = 0; char *qualstr = TextDatumGetCString(ev_qual); @@ -1627,250 +1624,6 @@ pg_get_indexdef_worker(Oid indexrelid, int colno, return buf.data; } -/* - * Return an index definition, split in several pieces. - * - * There is a huge lot of code that's a dupe of pg_get_indexdef_worker, but - * control flow is different enough that it doesn't seem worth keeping them - * together. - */ -void -pg_get_indexdef_detailed(Oid indexrelid, - char **index_am, - char **definition, - char **reloptions, - char **tablespace, - char **whereClause) -{ - HeapTuple ht_idx; - HeapTuple ht_idxrel; - HeapTuple ht_am; - Form_pg_index idxrec; - Form_pg_class idxrelrec; - Form_pg_am amrec; - IndexAmRoutine *amroutine; - List *indexprs; - ListCell *indexpr_item; - List *context; - Oid indrelid; - int keyno; - Datum indcollDatum; - Datum indclassDatum; - Datum indoptionDatum; - bool isnull; - oidvector *indcollation; - oidvector *indclass; - int2vector *indoption; - StringInfoData definitionBuf; - char *sep; - - /* - * Fetch the pg_index tuple by the Oid of the index - */ - ht_idx = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(indexrelid)); - if (!HeapTupleIsValid(ht_idx)) - elog(ERROR, "cache lookup failed for index %u", indexrelid); - idxrec = (Form_pg_index) GETSTRUCT(ht_idx); - - indrelid = idxrec->indrelid; - Assert(indexrelid == idxrec->indexrelid); - - /* Must get indcollation, indclass, and indoption the hard way */ - indcollDatum = SysCacheGetAttr(INDEXRELID, ht_idx, - Anum_pg_index_indcollation, &isnull); - Assert(!isnull); - indcollation = (oidvector *) DatumGetPointer(indcollDatum); - - indclassDatum = SysCacheGetAttr(INDEXRELID, ht_idx, - Anum_pg_index_indclass, &isnull); - Assert(!isnull); - indclass = (oidvector *) DatumGetPointer(indclassDatum); - - indoptionDatum = SysCacheGetAttr(INDEXRELID, ht_idx, - Anum_pg_index_indoption, &isnull); - Assert(!isnull); - indoption = (int2vector *) DatumGetPointer(indoptionDatum); - - /* - * Fetch the pg_class tuple of the index relation - */ - ht_idxrel = SearchSysCache1(RELOID, ObjectIdGetDatum(indexrelid)); - if (!HeapTupleIsValid(ht_idxrel)) - elog(ERROR, "cache lookup failed for relation %u", indexrelid); - idxrelrec = (Form_pg_class) GETSTRUCT(ht_idxrel); - - /* - * Fetch the pg_am tuple of the index' access method - */ - ht_am = SearchSysCache1(AMOID, ObjectIdGetDatum(idxrelrec->relam)); - if (!HeapTupleIsValid(ht_am)) - elog(ERROR, "cache lookup failed for access method %u", - idxrelrec->relam); - amrec = (Form_pg_am) GETSTRUCT(ht_am); - - /* Fetch the index AM's API struct */ - amroutine = GetIndexAmRoutine(amrec->amhandler); - - /* - * Get the index expressions, if any. (NOTE: we do not use the relcache - * versions of the expressions and predicate, because we want to display - * non-const-folded expressions.) - */ - if (!heap_attisnull(ht_idx, Anum_pg_index_indexprs, NULL)) - { - Datum exprsDatum; - bool isnull; - char *exprsString; - - exprsDatum = SysCacheGetAttr(INDEXRELID, ht_idx, - Anum_pg_index_indexprs, &isnull); - Assert(!isnull); - exprsString = TextDatumGetCString(exprsDatum); - indexprs = (List *) stringToNode(exprsString); - pfree(exprsString); - } - else - indexprs = NIL; - - indexpr_item = list_head(indexprs); - - context = deparse_context_for(get_relation_name(indrelid), indrelid); - - initStringInfo(&definitionBuf); - - /* output index AM */ - *index_am = pstrdup(quote_identifier(NameStr(amrec->amname))); - - /* - * Output index definition. Note the outer parens must be supplied by - * caller. - */ - sep = ""; - for (keyno = 0; keyno < idxrec->indnatts; keyno++) - { - AttrNumber attnum = idxrec->indkey.values[keyno]; - int16 opt = indoption->values[keyno]; - Oid keycoltype; - Oid keycolcollation; - - Oid indcoll; - - appendStringInfoString(&definitionBuf, sep); - sep = ", "; - - if (attnum != 0) - { - /* Simple index column */ - char *attname; - int32 keycoltypmod; - - attname = get_attname(indrelid, attnum, false); - appendStringInfoString(&definitionBuf, quote_identifier(attname)); - get_atttypetypmodcoll(indrelid, attnum, - &keycoltype, &keycoltypmod, - &keycolcollation); - } - else - { - /* expressional index */ - Node *indexkey; - char *str; - - if (indexpr_item == NULL) - elog(ERROR, "too few entries in indexprs list"); - indexkey = (Node *) lfirst(indexpr_item); - indexpr_item = lnext(indexprs, indexpr_item); - /* Deparse */ - str = deparse_expression_pretty(indexkey, context, false, false, - 0, 0); - - /* Need parens if it's not a bare function call */ - if (indexkey && IsA(indexkey, FuncExpr) && - ((FuncExpr *) indexkey)->funcformat == COERCE_EXPLICIT_CALL) - appendStringInfoString(&definitionBuf, str); - else - appendStringInfo(&definitionBuf, "(%s)", str); - - keycoltype = exprType(indexkey); - keycolcollation = exprCollation(indexkey); - } - - /* Add collation, even if default */ - indcoll = indcollation->values[keyno]; - if (OidIsValid(indcoll)) - appendStringInfo(&definitionBuf, " COLLATE %s", - generate_collation_name((indcoll))); - - /* Add the operator class name, even if default */ - get_opclass_name(indclass->values[keyno], InvalidOid, &definitionBuf); - - /* Add options if relevant */ - if (amroutine->amcanorder) - { - /* if it supports sort ordering, report DESC and NULLS opts */ - if (opt & INDOPTION_DESC) - { - appendStringInfoString(&definitionBuf, " DESC"); - /* NULLS FIRST is the default in this case */ - if (!(opt & INDOPTION_NULLS_FIRST)) - appendStringInfoString(&definitionBuf, " NULLS LAST"); - } - else - { - if (opt & INDOPTION_NULLS_FIRST) - appendStringInfoString(&definitionBuf, " NULLS FIRST"); - } - } - - /* XXX excludeOps thingy was here; do we need anything? */ - } - *definition = definitionBuf.data; - - /* output reloptions */ - *reloptions = flatten_reloptions(indexrelid); - - /* output tablespace */ - { - Oid tblspc; - - tblspc = get_rel_tablespace(indexrelid); - if (OidIsValid(tblspc)) - *tablespace = pstrdup(quote_identifier(get_tablespace_name(tblspc))); - else - *tablespace = NULL; - } - - /* report index predicate, if any */ - if (!heap_attisnull(ht_idx, Anum_pg_index_indpred, NULL)) - { - Node *node; - Datum predDatum; - bool isnull; - char *predString; - - /* Convert text string to node tree */ - predDatum = SysCacheGetAttr(INDEXRELID, ht_idx, - Anum_pg_index_indpred, &isnull); - Assert(!isnull); - predString = TextDatumGetCString(predDatum); - node = (Node *) stringToNode(predString); - pfree(predString); - - /* Deparse */ - *whereClause = - deparse_expression_pretty(node, context, false, false, - 0, 0); - } - else - *whereClause = NULL; - - /* Clean up */ - ReleaseSysCache(ht_idx); - ReleaseSysCache(ht_idxrel); - ReleaseSysCache(ht_am); - - /* all done */ -} /* ---------- * pg_get_querydef @@ -12331,7 +12084,7 @@ get_tablesample_def(TableSampleClause *tablesample, deparse_context *context) * actual_datatype. (If you don't want this behavior, just pass * InvalidOid for actual_datatype.) */ -static void +void get_opclass_name(Oid opclass, Oid actual_datatype, StringInfo buf) { @@ -13112,7 +12865,7 @@ get_reloptions(StringInfo buf, Datum reloptions) /* * Generate a C string representing a relation's reloptions, or NULL if none. */ -static char * +char * flatten_reloptions(Oid relid) { char *result = NULL; @@ -13180,73 +12933,3 @@ get_range_partbound_string(List *bound_datums) return buf->data; } - - -/* - * Obtain the deparsed default value for the given column of the given table. - * - * Caller must have set a correct deparse context. - */ -char * -RelationGetColumnDefault(Relation rel, AttrNumber attno, List *dpcontext) -{ - Node *defval; - char *defstr; - - defval = build_column_default(rel, attno); - defstr = deparse_expression_pretty(defval, dpcontext, false, false, - 0, 0); - - return defstr; -} - -/* - * Return the default value of a domain. - */ -char * -DomainGetDefault(HeapTuple domTup) -{ - Datum def; - Node *defval; - char *defstr; - bool isnull; - - def = SysCacheGetAttr(TYPEOID, domTup, Anum_pg_type_typdefaultbin, - &isnull); - if (isnull) - elog(ERROR, "domain \"%s\" does not have a default value", - NameStr(((Form_pg_type) GETSTRUCT(domTup))->typname)); - defval = stringToNode(TextDatumGetCString(def)); - defstr = deparse_expression_pretty(defval, NULL /* dpcontext? */, - false, false, 0, 0); - - return defstr; -} - - -/* - * Return the defaults values of arguments to a function, as a list of - * deparsed expressions. - */ -List * -FunctionGetDefaults(text *proargdefaults) -{ - List *nodedefs; - List *strdefs = NIL; - ListCell *cell; - - nodedefs = (List *) stringToNode(TextDatumGetCString(proargdefaults)); - if (!IsA(nodedefs, List)) - elog(ERROR, "proargdefaults is not a list"); - - foreach(cell, nodedefs) - { - Node *onedef = lfirst(cell); - - strdefs = lappend(strdefs, deparse_expression_pretty(onedef, NIL, false, false, 0, 0)); - } - - return strdefs; -} - - diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h index cde659f..d14bb8f 100644 --- a/src/include/utils/builtins.h +++ b/src/include/utils/builtins.h @@ -121,10 +121,6 @@ extern char *format_type_be_qualified(Oid type_oid); extern char *format_type_with_typemod(Oid type_oid, int32 typemod); extern int32 type_maximum_size(Oid type_oid, int32 typemod); -extern void format_type_detailed(Oid type_oid, int32 typemod, - Oid *nspid, char **typname, - char **typemodstr, bool *is_array); - /* quote.c */ extern char *quote_literal_cstr(const char *rawstr); diff --git a/src/include/utils/ruleutils.h b/src/include/utils/ruleutils.h index 83c242d..e359c90 100644 --- a/src/include/utils/ruleutils.h +++ b/src/include/utils/ruleutils.h @@ -24,17 +24,11 @@ struct PlannedStmt; extern char *pg_get_indexdef_string(Oid indexrelid); extern char *pg_get_indexdef_columns(Oid indexrelid, bool pretty); -extern void pg_get_indexdef_detailed(Oid indexrelid, - char **index_am, - char **definition, - char **reloptions, - char **tablespace, - char **whereClause); extern char *pg_get_trigger_whenclause(Form_pg_trigger trigrec, Node *whenClause, bool pretty); extern char *pg_get_constraintdef_string(Oid constraintId, bool fullCommand); extern char *pg_get_constraintdef_command(Oid constraintId); -extern void pg_get_ruledef_details(Datum ev_qual, Datum ev_action, +extern void pg_get_ruledef_detailed(Datum ev_qual, Datum ev_action, char **whereClause, List **actions); extern char *pg_get_viewdef_internal(Oid viewoid); extern char *pg_get_createtableas_def(Query *query); @@ -53,13 +47,10 @@ extern List *set_deparse_context_plan(List *dpcontext, struct Plan *plan, List *ancestors); extern List *select_rtable_names_for_explain(List *rtable, Bitmapset *rels_used); +extern void get_opclass_name(Oid opclass, Oid actual_datatype, + StringInfo buf); extern char *generate_collation_name(Oid collid); -extern List *FunctionGetDefaults(text *proargdefaults); - -extern char *RelationGetColumnDefault(Relation rel, AttrNumber attno, - List *dpcontext); - -extern char *DomainGetDefault(HeapTuple domTup); +extern char *flatten_reloptions(Oid relid); extern char *generate_opclass_name(Oid opclass); extern char *get_range_partbound_string(List *bound_datums); -- 1.8.3.1 [application/octet-stream] 0003-Add-optional-constraint-name-to-field-IndexStmt.patch (4.8K, ../../CAFPTHDaCp7-FRjkYnfjsBTUxrRX9P9f6t8TEhR1CZVoKHCwbTQ@mail.gmail.com/3-0003-Add-optional-constraint-name-to-field-IndexStmt.patch) download | inline diff: From c21130a0c1818cc70c2b5f82c6deec40bbd01534 Mon Sep 17 00:00:00 2001 From: Ajin Cherian <[email protected]> Date: Fri, 15 Apr 2022 11:17:39 -0400 Subject: [PATCH 3/3] Add optional constraint name to field IndexStmt And keep the original index name field intact when renaming. This appears to be the only way to trace back the original index name before it was renamed to match the constraint name. We need this information in the ddl_deparse module. --- src/backend/commands/tablecmds.c | 4 ++-- src/backend/nodes/copyfuncs.c | 1 + src/backend/nodes/equalfuncs.c | 1 + src/backend/nodes/outfuncs.c | 1 + src/backend/parser/parse_utilcmd.c | 16 ++++++++++++++-- src/include/nodes/parsenodes.h | 1 + 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 90edd0b..af2c963 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8692,7 +8692,7 @@ ATExecAddIndexConstraint(AlteredTableInfo *tab, Relation rel, indexRel = index_open(index_oid, AccessShareLock); - indexName = pstrdup(RelationGetRelationName(indexRel)); + indexName = stmt->idxname; indexInfo = BuildIndexInfo(indexRel); @@ -8707,7 +8707,7 @@ ATExecAddIndexConstraint(AlteredTableInfo *tab, Relation rel, * explicitly gives some other name for the constraint, rename the index * to match. */ - constraintName = stmt->idxname; + constraintName = stmt->conname; if (constraintName == NULL) constraintName = indexName; else if (strcmp(constraintName, indexName) != 0) diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 836f427..88254a5 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -4182,6 +4182,7 @@ _copyIndexStmt(const IndexStmt *from) IndexStmt *newnode = makeNode(IndexStmt); COPY_STRING_FIELD(idxname); + COPY_STRING_FIELD(conname); COPY_NODE_FIELD(relation); COPY_STRING_FIELD(accessMethod); COPY_STRING_FIELD(tableSpace); diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index e013c1b..888ab32 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -1740,6 +1740,7 @@ static bool _equalIndexStmt(const IndexStmt *a, const IndexStmt *b) { COMPARE_STRING_FIELD(idxname); + COMPARE_STRING_FIELD(conname); COMPARE_NODE_FIELD(relation); COMPARE_STRING_FIELD(accessMethod); COMPARE_STRING_FIELD(tableSpace); diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index d5f5e76..a8dedc4 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -2909,6 +2909,7 @@ _outIndexStmt(StringInfo str, const IndexStmt *node) WRITE_NODE_TYPE("INDEXSTMT"); WRITE_STRING_FIELD(idxname); + WRITE_STRING_FIELD(conname); WRITE_NODE_FIELD(relation); WRITE_STRING_FIELD(accessMethod); WRITE_STRING_FIELD(tableSpace); diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index 2826559..9139643 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -2128,6 +2128,10 @@ transformIndexConstraints(CreateStmtContext *cxt) */ if (priorindex->idxname == NULL) priorindex->idxname = index->idxname; + + if (priorindex->conname == NULL) + priorindex->conname = index->conname; + keep = false; break; } @@ -2186,10 +2190,17 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt) index->deferrable = constraint->deferrable; index->initdeferred = constraint->initdeferred; + index->idxname = NULL; /* by default, DefineIndex will choose name */ + if (constraint->conname != NULL) - index->idxname = pstrdup(constraint->conname); + { + index->conname = pstrdup(constraint->conname); + + if (constraint->indexname == NULL) + index->idxname = pstrdup(constraint->conname); + } else - index->idxname = NULL; /* DefineIndex will choose name */ + index->conname = NULL; index->relation = cxt->relation; index->accessMethod = constraint->access_method ? constraint->access_method : DEFAULT_INDEX_TYPE; @@ -2384,6 +2395,7 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt) relation_close(index_rel, NoLock); index->indexOid = index_oid; + index->idxname = pstrdup(index_name); } /* diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index da02658..dba0ab4 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3240,6 +3240,7 @@ typedef struct IndexStmt { NodeTag type; char *idxname; /* name of new index, or NULL for default */ + char *conname; /* corresponding constraint name, or NULL */ RangeVar *relation; /* relation to build index on */ char *accessMethod; /* name of access method (eg. btree) */ char *tableSpace; /* tablespace, or NULL for default */ -- 1.8.3.1 [application/octet-stream] 0001-ddl_deparse-core-support.patch (32.0K, ../../CAFPTHDaCp7-FRjkYnfjsBTUxrRX9P9f6t8TEhR1CZVoKHCwbTQ@mail.gmail.com/4-0001-ddl_deparse-core-support.patch) download | inline diff: From e3b589472cc8e299646f2bef3fbaeb486df37f9b Mon Sep 17 00:00:00 2001 From: Ajin Cherian <[email protected]> Date: Wed, 13 Apr 2022 00:08:10 -0400 Subject: [PATCH 1/3] ddl_deparse core support --- src/backend/catalog/objectaddress.c | 4 +- src/backend/commands/seclabel.c | 5 + src/backend/commands/sequence.c | 35 +++ src/backend/utils/adt/format_type.c | 125 +++++++++ src/backend/utils/adt/regproc.c | 104 +++++-- src/backend/utils/adt/ruleutils.c | 529 ++++++++++++++++++++++++++++++++---- src/include/commands/sequence.h | 1 + src/include/utils/builtins.h | 5 + src/include/utils/regproc.h | 3 +- src/include/utils/ruleutils.h | 23 +- 10 files changed, 746 insertions(+), 88 deletions(-) diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c index ac60435..36dfb0f 100644 --- a/src/backend/catalog/objectaddress.c +++ b/src/backend/catalog/objectaddress.c @@ -2980,7 +2980,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) { bits16 flags = FORMAT_PROC_INVALID_AS_NULL; char *proname = format_procedure_extended(object->objectId, - flags); + flags, false); if (proname == NULL) break; @@ -4826,7 +4826,7 @@ getObjectIdentityParts(const ObjectAddress *object, { bits16 flags = FORMAT_PROC_FORCE_QUALIFY | FORMAT_PROC_INVALID_AS_NULL; char *proname = format_procedure_extended(object->objectId, - flags); + flags, false); if (proname == NULL) break; diff --git a/src/backend/commands/seclabel.c b/src/backend/commands/seclabel.c index 7ae19b9..c1530a1 100644 --- a/src/backend/commands/seclabel.c +++ b/src/backend/commands/seclabel.c @@ -134,6 +134,11 @@ ExecSecLabelStmt(SecLabelStmt *stmt) (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("must specify provider when multiple security label providers have been loaded"))); provider = (LabelProvider *) linitial(label_provider_list); + /* + * Set the provider in the statement so that DDL deparse can use + * provider explicitly in generated statement. + */ + stmt->provider = (char *) provider->provider_name; } else { diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c index ddf219b..bdd081c 100644 --- a/src/backend/commands/sequence.c +++ b/src/backend/commands/sequence.c @@ -1699,6 +1699,41 @@ process_owned_by(Relation seqrel, List *owned_by, bool for_identity) relation_close(tablerel, NoLock); } +/* + * Return sequence parameters, detailed + */ + +Form_pg_sequence_data +get_sequence_values(Oid sequenceId) +{ + Buffer buf; + SeqTable elm; + Relation seqrel; + HeapTupleData seqtuple; + Form_pg_sequence_data seq; + Form_pg_sequence_data retSeq; + + retSeq = palloc(sizeof(FormData_pg_sequence)); + + /* open and AccessShareLock sequence */ + init_sequence(sequenceId, &elm, &seqrel); + + if (pg_class_aclcheck(sequenceId, GetUserId(), + ACL_SELECT | ACL_UPDATE | ACL_USAGE) != ACLCHECK_OK) + ereport(ERROR, + (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), + errmsg("permission denied for sequence %s", + RelationGetRelationName(seqrel)))); + + seq = read_seq_tuple(seqrel, &buf, &seqtuple); + + memcpy(retSeq, seq, sizeof(FormData_pg_sequence_data)); + + UnlockReleaseBuffer(buf); + relation_close(seqrel, NoLock); + + return retSeq; +} /* * Return sequence parameters in a list of the form created by the parser. diff --git a/src/backend/utils/adt/format_type.c b/src/backend/utils/adt/format_type.c index 060fd7e..42e3af3 100644 --- a/src/backend/utils/adt/format_type.c +++ b/src/backend/utils/adt/format_type.c @@ -334,6 +334,131 @@ format_type_extended(Oid type_oid, int32 typemod, bits16 flags) } /* + * Similar to format_type_internal, except we return each bit of information + * separately: + * + * - nspid is the schema OID. For certain SQL-standard types which have weird + * typmod rules, we return InvalidOid; caller is expected to not schema- + * qualify the name nor add quotes to the type name in this case. + * + * - typename is set to the type name, without quotes + * + * - typmod is set to the typemod, if any, as a string with parens + * + * - typarray indicates whether []s must be added + * + * We don't try to decode type names to their standard-mandated names, except + * in the cases of types with unusual typmod rules. + */ +void +format_type_detailed(Oid type_oid, int32 typemod, + Oid *nspid, char **typname, char **typemodstr, + bool *typarray) +{ + HeapTuple tuple; + Form_pg_type typeform; + Oid array_base_type; + + tuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(type_oid)); + if (!HeapTupleIsValid(tuple)) + elog(ERROR, "cache lookup failed for type %u", type_oid); + + typeform = (Form_pg_type) GETSTRUCT(tuple); + + /* * Special-case crock for types with strange typmod rules. + */ + if (type_oid == INTERVALOID || + type_oid == TIMESTAMPOID || + type_oid == TIMESTAMPTZOID || + type_oid == TIMEOID || + type_oid == TIMETZOID) + { + *typarray = false; + +peculiar_typmod: + switch (type_oid) + { + case INTERVALOID: + *typname = pstrdup("INTERVAL"); + break; + case TIMESTAMPTZOID: + if (typemod < 0) + { + *typname = pstrdup("TIMESTAMP WITH TIME ZONE"); + break; + } + /* otherwise, WITH TZ is added by typmod, so fall through */ + case TIMESTAMPOID: + *typname = pstrdup("TIMESTAMP"); + break; + case TIMETZOID: + if (typemod < 0) + { + *typname = pstrdup("TIME WITH TIME ZONE"); + break; + } + /* otherwise, WITH TZ is added by typmode, so fall through */ + case TIMEOID: + *typname = pstrdup("TIME"); + break; + } + *nspid = InvalidOid; + + if (typemod >= 0) + *typemodstr = printTypmod(NULL, typemod, typeform->typmodout); + else + *typemodstr = pstrdup(""); + + ReleaseSysCache(tuple); + return; + } + + /* + * Check if it's a regular (variable length) array type. As above, + * fixed-length array types such as "name" shouldn't get deconstructed. + */ + array_base_type = typeform->typelem; + + if (array_base_type != InvalidOid && + typeform->typstorage != 'p') + { + /* Switch our attention to the array element type */ + ReleaseSysCache(tuple); + tuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(array_base_type)); + if (!HeapTupleIsValid(tuple)) + elog(ERROR, "cache lookup failed for type %u", type_oid); + + typeform = (Form_pg_type) GETSTRUCT(tuple); + type_oid = array_base_type; + *typarray = true; + + /* + * If it's an array of one of the types with special typmod rules, + * have the element type be processed as above, but now with typarray + * set to true. + */ + if (type_oid == INTERVALOID || + type_oid == TIMESTAMPTZOID || + type_oid == TIMESTAMPOID || + type_oid == TIMETZOID || + type_oid == TIMEOID) + goto peculiar_typmod; + } + else + *typarray = false; + + *nspid = typeform->typnamespace; + *typname = pstrdup(NameStr(typeform->typname)); + + if (typemod >= 0) + *typemodstr = printTypmod(NULL, typemod, typeform->typmodout); + else + *typemodstr = pstrdup(""); + + ReleaseSysCache(tuple); +} + +/* * This version is for use within the backend in error messages, etc. * One difference is that it will fail for an invalid type. * diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c index 6d4c1c2..4df3256 100644 --- a/src/backend/utils/adt/regproc.c +++ b/src/backend/utils/adt/regproc.c @@ -43,7 +43,8 @@ static void parseNameAndArgTypes(const char *string, bool allowNone, List **names, int *nargs, Oid *argtypes); - +static void format_procedure_args_internal(Form_pg_proc procform, + StringInfo buf, bool force_qualify); /***************************************************************************** * USER I/O ROUTINES * @@ -322,13 +323,37 @@ to_regprocedure(PG_FUNCTION_ARGS) char * format_procedure(Oid procedure_oid) { - return format_procedure_extended(procedure_oid, 0); + return format_procedure_extended(procedure_oid, 0, false); } char * format_procedure_qualified(Oid procedure_oid) { - return format_procedure_extended(procedure_oid, FORMAT_PROC_FORCE_QUALIFY); + return format_procedure_extended(procedure_oid, true, false); +} + +/* + * format_procedure_args - converts proc OID to "(args)" + */ +char * +format_procedure_args(Oid procedure_oid, bool force_qualify) +{ + StringInfoData buf; + HeapTuple proctup; + Form_pg_proc procform; + + proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procedure_oid)); + if (!HeapTupleIsValid(proctup)) + elog(ERROR, "cache lookup failed for procedure %u", procedure_oid); + procform = (Form_pg_proc) GETSTRUCT(proctup); + + + initStringInfo(&buf); + format_procedure_args_internal(procform, &buf, force_qualify); + + ReleaseSysCache(proctup); + + return buf.data; } /* @@ -347,10 +372,13 @@ format_procedure_qualified(Oid procedure_oid) * always schema-qualify procedure names, regardless of search_path */ char * -format_procedure_extended(Oid procedure_oid, bits16 flags) +format_procedure_extended(Oid procedure_oid, bits16 flags, bool args_only) { char *result; HeapTuple proctup; + bool force_qualify; + + force_qualify = (flags & FORMAT_PROC_FORCE_QUALIFY) != 0; proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procedure_oid)); @@ -358,8 +386,6 @@ format_procedure_extended(Oid procedure_oid, bits16 flags) { Form_pg_proc procform = (Form_pg_proc) GETSTRUCT(proctup); char *proname = NameStr(procform->proname); - int nargs = procform->pronargs; - int i; char *nspname; StringInfoData buf; @@ -368,30 +394,25 @@ format_procedure_extended(Oid procedure_oid, bits16 flags) initStringInfo(&buf); - /* - * Would this proc be found (given the right args) by regprocedurein? - * If not, or if caller requests it, we need to qualify it. - */ - if ((flags & FORMAT_PROC_FORCE_QUALIFY) == 0 && - FunctionIsVisible(procedure_oid)) - nspname = NULL; - else - nspname = get_namespace_name(procform->pronamespace); - - appendStringInfo(&buf, "%s(", - quote_qualified_identifier(nspname, proname)); - for (i = 0; i < nargs; i++) + if (!args_only) { - Oid thisargtype = procform->proargtypes.values[i]; - - if (i > 0) - appendStringInfoChar(&buf, ','); - appendStringInfoString(&buf, - (flags & FORMAT_PROC_FORCE_QUALIFY) != 0 ? - format_type_be_qualified(thisargtype) : - format_type_be(thisargtype)); + + /* + * Would this proc be found (given the right args) by regprocedurein? + * If not, or if caller requests it, we need to qualify it. + */ + if ((flags & FORMAT_PROC_FORCE_QUALIFY) == 0 && + FunctionIsVisible(procedure_oid)) + nspname = NULL; + else + nspname = get_namespace_name(procform->pronamespace); + + appendStringInfo(&buf, "%s", + quote_qualified_identifier(nspname, proname)); } - appendStringInfoChar(&buf, ')'); + + /* add the attributes */ + format_procedure_args_internal(procform, &buf, force_qualify); result = buf.data; @@ -413,6 +434,33 @@ format_procedure_extended(Oid procedure_oid, bits16 flags) } /* + * Append the parenthised arguments of the given pg_proc row into the output + * buffer. force_qualify indicates whether to schema-qualify type names + * regardless of visibility. + */ +static void +format_procedure_args_internal(Form_pg_proc procform, StringInfo buf, + bool force_qualify) +{ + int i; + int nargs = procform->pronargs; + + appendStringInfoChar(buf, '('); + for (i = 0; i < nargs; i++) + { + Oid thisargtype = procform->proargtypes.values[i]; + + if (i > 0) + appendStringInfoChar(buf, ','); + appendStringInfoString(buf, + force_qualify ? + format_type_be_qualified(thisargtype) : + format_type_be(thisargtype)); + } + appendStringInfoChar(buf, ')'); +} + +/* * Output an objname/objargs representation for the procedure with the * given OID. If it doesn't exist, an error is thrown. * diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 3296ad0..f1d6e9a 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -551,6 +551,78 @@ pg_get_ruledef_ext(PG_FUNCTION_ARGS) PG_RETURN_TEXT_P(string_to_text(res)); } +/* + * Given a pair of Datum corresponding to a rule's pg_rewrite.ev_qual and + * ev_action columns, return their text representation; ev_qual as a single + * string in whereClause and ev_action as a List of strings (which might be + * NIL, signalling NOTHING) in actions. + */ +void +pg_get_ruledef_details(Datum ev_qual, Datum ev_action, + char **whereClause, List **actions) +{ + int prettyFlags = 0; + char *qualstr = TextDatumGetCString(ev_qual); + char *actionstr = TextDatumGetCString(ev_action); + List *actionNodeList = (List *) stringToNode(actionstr); + StringInfoData buf; + + initStringInfo(&buf); + if (strlen(qualstr) > 0 && strcmp(qualstr, "<>") != 0) + { + Node *qual; + Query *query; + deparse_context context; + deparse_namespace dpns; + + qual = stringToNode(qualstr); + + query = (Query *) linitial(actionNodeList); + query = getInsertSelectQuery(query, NULL); + + AcquireRewriteLocks(query, false, false); + + context.buf = &buf; + context.namespaces = list_make1(&dpns); + context.windowClause = NIL; + context.windowTList = NIL; + context.varprefix = (list_length(query->rtable) != 1); + context.prettyFlags = prettyFlags; + context.wrapColumn = WRAP_COLUMN_DEFAULT; + context.indentLevel = PRETTYINDENT_STD; + + set_deparse_for_query(&dpns, query, NIL); + + get_rule_expr(qual, &context, false); + + *whereClause = pstrdup(buf.data); + } + else + *whereClause = NULL; + + if (list_length(actionNodeList) == 0) + *actions = NIL; + else + { + ListCell *cell; + List *output = NIL; + + foreach(cell, actionNodeList) + { + Query *query = (Query *) lfirst(cell); + + if (query->commandType == CMD_NOTHING) + continue; + + resetStringInfo(&buf); + get_query_def(query, &buf, NIL, NULL, + prettyFlags, WRAP_COLUMN_DEFAULT, 0); + output = lappend(output, pstrdup(buf.data)); + } + *actions = output; + } +} + static char * pg_get_ruledef_worker(Oid ruleoid, int prettyFlags) @@ -742,6 +814,14 @@ pg_get_viewdef_name_ext(PG_FUNCTION_ARGS) PG_RETURN_TEXT_P(string_to_text(res)); } +char * +pg_get_viewdef_internal(Oid viewoid) +{ + + return pg_get_viewdef_worker(viewoid, 0, WRAP_COLUMN_DEFAULT); + +} + /* * Common code for by-OID and by-name variants of pg_get_viewdef */ @@ -824,6 +904,21 @@ pg_get_viewdef_worker(Oid viewoid, int prettyFlags, int wrapColumn) return buf.data; } +/* + * get_createtableas_def - Get the accompanying query for a CREATE TABLE AS + */ +char * +pg_get_createtableas_def(Query *query) +{ + StringInfoData buf; + + initStringInfo(&buf); + + get_query_def(query, &buf, NIL, NULL, 0, 0, 0); + + return buf.data; +} + /* ---------- * pg_get_triggerdef - Get the definition of a trigger * ---------- @@ -1021,65 +1116,12 @@ pg_get_triggerdef_worker(Oid trigid, bool pretty) if (!isnull) { Node *qual; - char relkind; - deparse_context context; - deparse_namespace dpns; - RangeTblEntry *oldrte; - RangeTblEntry *newrte; - - appendStringInfoString(&buf, "WHEN ("); + char *qualstr; qual = stringToNode(TextDatumGetCString(value)); + qualstr = pg_get_trigger_whenclause(trigrec, qual, pretty); - relkind = get_rel_relkind(trigrec->tgrelid); - - /* Build minimal OLD and NEW RTEs for the rel */ - oldrte = makeNode(RangeTblEntry); - oldrte->rtekind = RTE_RELATION; - oldrte->relid = trigrec->tgrelid; - oldrte->relkind = relkind; - oldrte->rellockmode = AccessShareLock; - oldrte->alias = makeAlias("old", NIL); - oldrte->eref = oldrte->alias; - oldrte->lateral = false; - oldrte->inh = false; - oldrte->inFromCl = true; - - newrte = makeNode(RangeTblEntry); - newrte->rtekind = RTE_RELATION; - newrte->relid = trigrec->tgrelid; - newrte->relkind = relkind; - newrte->rellockmode = AccessShareLock; - newrte->alias = makeAlias("new", NIL); - newrte->eref = newrte->alias; - newrte->lateral = false; - newrte->inh = false; - newrte->inFromCl = true; - - /* Build two-element rtable */ - memset(&dpns, 0, sizeof(dpns)); - dpns.rtable = list_make2(oldrte, newrte); - dpns.subplans = NIL; - dpns.ctes = NIL; - dpns.appendrels = NULL; - set_rtable_names(&dpns, NIL, NULL); - set_simple_column_names(&dpns); - - /* Set up context with one-deep namespace stack */ - context.buf = &buf; - context.namespaces = list_make1(&dpns); - context.windowClause = NIL; - context.windowTList = NIL; - context.varprefix = true; - context.prettyFlags = GET_PRETTY_FLAGS(pretty); - context.wrapColumn = WRAP_COLUMN_DEFAULT; - context.indentLevel = PRETTYINDENT_STD; - context.special_exprkind = EXPR_KIND_NONE; - context.appendparents = NULL; - - get_rule_expr(qual, &context, false); - - appendStringInfoString(&buf, ") "); + appendStringInfo(&buf, "WHEN (%s) ", qualstr); } appendStringInfo(&buf, "EXECUTE FUNCTION %s(", @@ -1120,6 +1162,64 @@ pg_get_triggerdef_worker(Oid trigid, bool pretty) return buf.data; } +char * +pg_get_trigger_whenclause(Form_pg_trigger trigrec, Node *whenClause, bool pretty) +{ + StringInfoData buf; + char relkind; + deparse_context context; + deparse_namespace dpns; + RangeTblEntry *oldrte; + RangeTblEntry *newrte; + + initStringInfo(&buf); + + relkind = get_rel_relkind(trigrec->tgrelid); + + /* Build minimal OLD and NEW RTEs for the rel */ + oldrte = makeNode(RangeTblEntry); + oldrte->rtekind = RTE_RELATION; + oldrte->relid = trigrec->tgrelid; + oldrte->relkind = relkind; + oldrte->alias = makeAlias("old", NIL); + oldrte->eref = oldrte->alias; + oldrte->lateral = false; + oldrte->inh = false; + oldrte->inFromCl = true; + + newrte = makeNode(RangeTblEntry); + newrte->rtekind = RTE_RELATION; + newrte->relid = trigrec->tgrelid; + newrte->relkind = relkind; + newrte->alias = makeAlias("new", NIL); + newrte->eref = newrte->alias; + newrte->lateral = false; + newrte->inh = false; + newrte->inFromCl = true; + + /* Build two-element rtable */ + memset(&dpns, 0, sizeof(dpns)); + dpns.rtable = list_make2(oldrte, newrte); + dpns.ctes = NIL; + set_rtable_names(&dpns, NIL, NULL); + set_simple_column_names(&dpns); + + /* Set up context with one-deep namespace stack */ + context.buf = &buf; + context.namespaces = list_make1(&dpns); + context.windowClause = NIL; + context.windowTList = NIL; + context.varprefix = true; + context.prettyFlags = pretty ? PRETTYFLAG_PAREN | PRETTYFLAG_INDENT : PRETTYFLAG_INDENT; + context.wrapColumn = WRAP_COLUMN_DEFAULT; + context.indentLevel = PRETTYINDENT_STD; + context.special_exprkind = EXPR_KIND_NONE; + + get_rule_expr(whenClause, &context, false); + + return buf.data; +} + /* ---------- * pg_get_indexdef - Get the definition of an index * @@ -1207,6 +1307,8 @@ pg_get_indexdef_columns(Oid indexrelid, bool pretty) * * This is now used for exclusion constraints as well: if excludeOps is not * NULL then it points to an array of exclusion operator OIDs. + * + * XXX if you change this function, see pg_get_indexdef_detailed too. */ static char * pg_get_indexdef_worker(Oid indexrelid, int colno, @@ -1525,6 +1627,251 @@ pg_get_indexdef_worker(Oid indexrelid, int colno, return buf.data; } +/* + * Return an index definition, split in several pieces. + * + * There is a huge lot of code that's a dupe of pg_get_indexdef_worker, but + * control flow is different enough that it doesn't seem worth keeping them + * together. + */ +void +pg_get_indexdef_detailed(Oid indexrelid, + char **index_am, + char **definition, + char **reloptions, + char **tablespace, + char **whereClause) +{ + HeapTuple ht_idx; + HeapTuple ht_idxrel; + HeapTuple ht_am; + Form_pg_index idxrec; + Form_pg_class idxrelrec; + Form_pg_am amrec; + IndexAmRoutine *amroutine; + List *indexprs; + ListCell *indexpr_item; + List *context; + Oid indrelid; + int keyno; + Datum indcollDatum; + Datum indclassDatum; + Datum indoptionDatum; + bool isnull; + oidvector *indcollation; + oidvector *indclass; + int2vector *indoption; + StringInfoData definitionBuf; + char *sep; + + /* + * Fetch the pg_index tuple by the Oid of the index + */ + ht_idx = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(indexrelid)); + if (!HeapTupleIsValid(ht_idx)) + elog(ERROR, "cache lookup failed for index %u", indexrelid); + idxrec = (Form_pg_index) GETSTRUCT(ht_idx); + + indrelid = idxrec->indrelid; + Assert(indexrelid == idxrec->indexrelid); + + /* Must get indcollation, indclass, and indoption the hard way */ + indcollDatum = SysCacheGetAttr(INDEXRELID, ht_idx, + Anum_pg_index_indcollation, &isnull); + Assert(!isnull); + indcollation = (oidvector *) DatumGetPointer(indcollDatum); + + indclassDatum = SysCacheGetAttr(INDEXRELID, ht_idx, + Anum_pg_index_indclass, &isnull); + Assert(!isnull); + indclass = (oidvector *) DatumGetPointer(indclassDatum); + + indoptionDatum = SysCacheGetAttr(INDEXRELID, ht_idx, + Anum_pg_index_indoption, &isnull); + Assert(!isnull); + indoption = (int2vector *) DatumGetPointer(indoptionDatum); + + /* + * Fetch the pg_class tuple of the index relation + */ + ht_idxrel = SearchSysCache1(RELOID, ObjectIdGetDatum(indexrelid)); + if (!HeapTupleIsValid(ht_idxrel)) + elog(ERROR, "cache lookup failed for relation %u", indexrelid); + idxrelrec = (Form_pg_class) GETSTRUCT(ht_idxrel); + + /* + * Fetch the pg_am tuple of the index' access method + */ + ht_am = SearchSysCache1(AMOID, ObjectIdGetDatum(idxrelrec->relam)); + if (!HeapTupleIsValid(ht_am)) + elog(ERROR, "cache lookup failed for access method %u", + idxrelrec->relam); + amrec = (Form_pg_am) GETSTRUCT(ht_am); + + /* Fetch the index AM's API struct */ + amroutine = GetIndexAmRoutine(amrec->amhandler); + + /* + * Get the index expressions, if any. (NOTE: we do not use the relcache + * versions of the expressions and predicate, because we want to display + * non-const-folded expressions.) + */ + if (!heap_attisnull(ht_idx, Anum_pg_index_indexprs, NULL)) + { + Datum exprsDatum; + bool isnull; + char *exprsString; + + exprsDatum = SysCacheGetAttr(INDEXRELID, ht_idx, + Anum_pg_index_indexprs, &isnull); + Assert(!isnull); + exprsString = TextDatumGetCString(exprsDatum); + indexprs = (List *) stringToNode(exprsString); + pfree(exprsString); + } + else + indexprs = NIL; + + indexpr_item = list_head(indexprs); + + context = deparse_context_for(get_relation_name(indrelid), indrelid); + + initStringInfo(&definitionBuf); + + /* output index AM */ + *index_am = pstrdup(quote_identifier(NameStr(amrec->amname))); + + /* + * Output index definition. Note the outer parens must be supplied by + * caller. + */ + sep = ""; + for (keyno = 0; keyno < idxrec->indnatts; keyno++) + { + AttrNumber attnum = idxrec->indkey.values[keyno]; + int16 opt = indoption->values[keyno]; + Oid keycoltype; + Oid keycolcollation; + + Oid indcoll; + + appendStringInfoString(&definitionBuf, sep); + sep = ", "; + + if (attnum != 0) + { + /* Simple index column */ + char *attname; + int32 keycoltypmod; + + attname = get_attname(indrelid, attnum, false); + appendStringInfoString(&definitionBuf, quote_identifier(attname)); + get_atttypetypmodcoll(indrelid, attnum, + &keycoltype, &keycoltypmod, + &keycolcollation); + } + else + { + /* expressional index */ + Node *indexkey; + char *str; + + if (indexpr_item == NULL) + elog(ERROR, "too few entries in indexprs list"); + indexkey = (Node *) lfirst(indexpr_item); + indexpr_item = lnext(indexprs, indexpr_item); + /* Deparse */ + str = deparse_expression_pretty(indexkey, context, false, false, + 0, 0); + + /* Need parens if it's not a bare function call */ + if (indexkey && IsA(indexkey, FuncExpr) && + ((FuncExpr *) indexkey)->funcformat == COERCE_EXPLICIT_CALL) + appendStringInfoString(&definitionBuf, str); + else + appendStringInfo(&definitionBuf, "(%s)", str); + + keycoltype = exprType(indexkey); + keycolcollation = exprCollation(indexkey); + } + + /* Add collation, even if default */ + indcoll = indcollation->values[keyno]; + if (OidIsValid(indcoll)) + appendStringInfo(&definitionBuf, " COLLATE %s", + generate_collation_name((indcoll))); + + /* Add the operator class name, even if default */ + get_opclass_name(indclass->values[keyno], InvalidOid, &definitionBuf); + + /* Add options if relevant */ + if (amroutine->amcanorder) + { + /* if it supports sort ordering, report DESC and NULLS opts */ + if (opt & INDOPTION_DESC) + { + appendStringInfoString(&definitionBuf, " DESC"); + /* NULLS FIRST is the default in this case */ + if (!(opt & INDOPTION_NULLS_FIRST)) + appendStringInfoString(&definitionBuf, " NULLS LAST"); + } + else + { + if (opt & INDOPTION_NULLS_FIRST) + appendStringInfoString(&definitionBuf, " NULLS FIRST"); + } + } + + /* XXX excludeOps thingy was here; do we need anything? */ + } + *definition = definitionBuf.data; + + /* output reloptions */ + *reloptions = flatten_reloptions(indexrelid); + + /* output tablespace */ + { + Oid tblspc; + + tblspc = get_rel_tablespace(indexrelid); + if (OidIsValid(tblspc)) + *tablespace = pstrdup(quote_identifier(get_tablespace_name(tblspc))); + else + *tablespace = NULL; + } + + /* report index predicate, if any */ + if (!heap_attisnull(ht_idx, Anum_pg_index_indpred, NULL)) + { + Node *node; + Datum predDatum; + bool isnull; + char *predString; + + /* Convert text string to node tree */ + predDatum = SysCacheGetAttr(INDEXRELID, ht_idx, + Anum_pg_index_indpred, &isnull); + Assert(!isnull); + predString = TextDatumGetCString(predDatum); + node = (Node *) stringToNode(predString); + pfree(predString); + + /* Deparse */ + *whereClause = + deparse_expression_pretty(node, context, false, false, + 0, 0); + } + else + *whereClause = NULL; + + /* Clean up */ + ReleaseSysCache(ht_idx); + ReleaseSysCache(ht_idxrel); + ReleaseSysCache(ht_am); + + /* all done */ +} + /* ---------- * pg_get_querydef * @@ -12833,3 +13180,73 @@ get_range_partbound_string(List *bound_datums) return buf->data; } + + +/* + * Obtain the deparsed default value for the given column of the given table. + * + * Caller must have set a correct deparse context. + */ +char * +RelationGetColumnDefault(Relation rel, AttrNumber attno, List *dpcontext) +{ + Node *defval; + char *defstr; + + defval = build_column_default(rel, attno); + defstr = deparse_expression_pretty(defval, dpcontext, false, false, + 0, 0); + + return defstr; +} + +/* + * Return the default value of a domain. + */ +char * +DomainGetDefault(HeapTuple domTup) +{ + Datum def; + Node *defval; + char *defstr; + bool isnull; + + def = SysCacheGetAttr(TYPEOID, domTup, Anum_pg_type_typdefaultbin, + &isnull); + if (isnull) + elog(ERROR, "domain \"%s\" does not have a default value", + NameStr(((Form_pg_type) GETSTRUCT(domTup))->typname)); + defval = stringToNode(TextDatumGetCString(def)); + defstr = deparse_expression_pretty(defval, NULL /* dpcontext? */, + false, false, 0, 0); + + return defstr; +} + + +/* + * Return the defaults values of arguments to a function, as a list of + * deparsed expressions. + */ +List * +FunctionGetDefaults(text *proargdefaults) +{ + List *nodedefs; + List *strdefs = NIL; + ListCell *cell; + + nodedefs = (List *) stringToNode(TextDatumGetCString(proargdefaults)); + if (!IsA(nodedefs, List)) + elog(ERROR, "proargdefaults is not a list"); + + foreach(cell, nodedefs) + { + Node *onedef = lfirst(cell); + + strdefs = lappend(strdefs, deparse_expression_pretty(onedef, NIL, false, false, 0, 0)); + } + + return strdefs; +} + + diff --git a/src/include/commands/sequence.h b/src/include/commands/sequence.h index 9da2300..2875106 100644 --- a/src/include/commands/sequence.h +++ b/src/include/commands/sequence.h @@ -54,6 +54,7 @@ typedef struct xl_seq_rec extern int64 nextval_internal(Oid relid, bool check_permissions); extern Datum nextval(PG_FUNCTION_ARGS); extern List *sequence_options(Oid relid); +extern Form_pg_sequence_data get_sequence_values(Oid sequenceId); extern ObjectAddress DefineSequence(ParseState *pstate, CreateSeqStmt *stmt); extern ObjectAddress AlterSequence(ParseState *pstate, AlterSeqStmt *stmt); diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h index 666e545..cde659f 100644 --- a/src/include/utils/builtins.h +++ b/src/include/utils/builtins.h @@ -115,11 +115,16 @@ extern Datum numeric_float8_no_overflow(PG_FUNCTION_ARGS); #define FORMAT_TYPE_INVALID_AS_NULL 0x08 /* NULL if undefined */ extern char *format_type_extended(Oid type_oid, int32 typemod, bits16 flags); +extern char *format_procedure_args(Oid procedure_oid, bool force_qualify); extern char *format_type_be(Oid type_oid); extern char *format_type_be_qualified(Oid type_oid); extern char *format_type_with_typemod(Oid type_oid, int32 typemod); extern int32 type_maximum_size(Oid type_oid, int32 typemod); +extern void format_type_detailed(Oid type_oid, int32 typemod, + Oid *nspid, char **typname, + char **typemodstr, bool *is_array); + /* quote.c */ extern char *quote_literal_cstr(const char *rawstr); diff --git a/src/include/utils/regproc.h b/src/include/utils/regproc.h index a36ceba..f4d543d 100644 --- a/src/include/utils/regproc.h +++ b/src/include/utils/regproc.h @@ -18,7 +18,8 @@ /* Control flags for format_procedure_extended */ #define FORMAT_PROC_INVALID_AS_NULL 0x01 /* NULL if undefined */ #define FORMAT_PROC_FORCE_QUALIFY 0x02 /* force qualification */ -extern char *format_procedure_extended(Oid procedure_oid, bits16 flags); +extern char *format_procedure_extended(Oid procedure_oid, bits16 flags, + bool args_only); /* Control flags for format_operator_extended */ #define FORMAT_OPERATOR_INVALID_AS_NULL 0x01 /* NULL if undefined */ diff --git a/src/include/utils/ruleutils.h b/src/include/utils/ruleutils.h index 7d48971..83c242d 100644 --- a/src/include/utils/ruleutils.h +++ b/src/include/utils/ruleutils.h @@ -13,6 +13,7 @@ #ifndef RULEUTILS_H #define RULEUTILS_H +#include "catalog/pg_trigger.h" #include "nodes/nodes.h" #include "nodes/parsenodes.h" #include "nodes/pg_list.h" @@ -23,12 +24,26 @@ struct PlannedStmt; extern char *pg_get_indexdef_string(Oid indexrelid); extern char *pg_get_indexdef_columns(Oid indexrelid, bool pretty); +extern void pg_get_indexdef_detailed(Oid indexrelid, + char **index_am, + char **definition, + char **reloptions, + char **tablespace, + char **whereClause); +extern char *pg_get_trigger_whenclause(Form_pg_trigger trigrec, + Node *whenClause, bool pretty); +extern char *pg_get_constraintdef_string(Oid constraintId, bool fullCommand); +extern char *pg_get_constraintdef_command(Oid constraintId); +extern void pg_get_ruledef_details(Datum ev_qual, Datum ev_action, + char **whereClause, List **actions); +extern char *pg_get_viewdef_internal(Oid viewoid); +extern char *pg_get_createtableas_def(Query *query); + extern char *pg_get_querydef(Query *query, bool pretty); extern char *pg_get_partkeydef_columns(Oid relid, bool pretty); extern char *pg_get_partconstrdef_string(Oid partitionId, char *aliasname); -extern char *pg_get_constraintdef_command(Oid constraintId); extern char *deparse_expression(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit); extern List *deparse_context_for(const char *aliasname, Oid relid); @@ -39,6 +54,12 @@ extern List *set_deparse_context_plan(List *dpcontext, extern List *select_rtable_names_for_explain(List *rtable, Bitmapset *rels_used); extern char *generate_collation_name(Oid collid); +extern List *FunctionGetDefaults(text *proargdefaults); + +extern char *RelationGetColumnDefault(Relation rel, AttrNumber attno, + List *dpcontext); + +extern char *DomainGetDefault(HeapTuple domTup); extern char *generate_opclass_name(Oid opclass); extern char *get_range_partbound_string(List *bound_datums); -- 1.8.3.1 ^ permalink raw reply [nested|flat] 97+ messages in thread
end of thread, other threads:[~2022-04-15 16:40 UTC | newest] Thread overview: 97+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2021-03-04 23:16 [PATCH 1/8] introduce bsearch_arg Tomas Vondra <[email protected]> 2022-04-15 16:40 Re: deparsing utility commands Ajin Cherian <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox