public inbox for [email protected]
help / color / mirror / Atom feed[PATCH 1/8] introduce bsearch_arg
3+ messages / 3 participants
[nested] [flat]
* [PATCH 1/8] introduce bsearch_arg
@ 2021-03-04 23:16 Tomas Vondra <[email protected]>
0 siblings, 0 replies; 3+ 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] 3+ messages in thread
* A failure in prepared_xacts test
@ 2024-04-29 01:12 Richard Guo <[email protected]>
0 siblings, 1 reply; 3+ messages in thread
From: Richard Guo @ 2024-04-29 01:12 UTC (permalink / raw)
To: pgsql-hackers
Yesterday I noticed a failure on cirrus-ci for the 'Right Semi Join'
patch. The failure can be found at [1], and it looks like:
--- /tmp/cirrus-ci-build/src/test/regress/expected/prepared_xacts.out
2024-04-27 00:41:25.831297000 +0000
+++
/tmp/cirrus-ci-build/build/testrun/regress-running/regress/results/prepared_xacts.out
2024-04-27 00:45:50.261369000 +0000
@@ -83,8 +83,9 @@
SELECT gid FROM pg_prepared_xacts;
gid
------
+ gxid
foo3
-(1 row)
+(2 rows)
Upon closer look, it seems that this issue is not caused by the patch
about 'Right Semi Join', because this query, which initially included
two left joins, can actually be reduced to a function scan after
removing these two useless left joins. It seems that no semi-joins
would be involved.
EXPLAIN SELECT gid FROM pg_prepared_xacts;
QUERY PLAN
----------------------------------------------------------------------------
Function Scan on pg_prepared_xact p (cost=0.00..10.00 rows=1000 width=32)
(1 row)
Does anyone have any clue to this failure?
FWIW, after another run of this test, the failure just disappears. Does
it suggest that the test case is flaky?
[1]
https://api.cirrus-ci.com/v1/artifact/task/6220592364388352/testrun/build/testrun/regress-running/re...
Thanks
Richard
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: A failure in prepared_xacts test
@ 2024-04-29 05:00 Alexander Lakhin <[email protected]>
parent: Richard Guo <[email protected]>
0 siblings, 0 replies; 3+ messages in thread
From: Alexander Lakhin @ 2024-04-29 05:00 UTC (permalink / raw)
To: Richard Guo <[email protected]>; pgsql-hackers
Hello Richard,
29.04.2024 04:12, Richard Guo wrote:
> Does anyone have any clue to this failure?
>
> FWIW, after another run of this test, the failure just disappears. Does
> it suggest that the test case is flaky?
>
I think this could be caused by the ecpg test twophase executed
simultaneously with the test prepared_xacts thanks to meson's jobs
parallelization.
Best regards,
Alexander
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2024-04-29 05:00 UTC | newest]
Thread overview: 3+ 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]>
2024-04-29 01:12 A failure in prepared_xacts test Richard Guo <[email protected]>
2024-04-29 05:00 ` Re: A failure in prepared_xacts test Alexander Lakhin <[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