From: | "Matwey V(dot) Kornilov" <matwey(dot)kornilov(at)gmail(dot)com> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Cc: | "Matwey V(dot) Kornilov" <matwey(dot)kornilov(at)gmail(dot)com>, akorotkov(at)postgresql(dot)org, teodor(at)postgrespro(dot)ru |
Subject: | [PATCH 2/3] Introduce spg_quad_inner_consistent_box_helper() in spgquadtreeproc.c |
Date: | 2019-02-01 16:07:59 |
Message-ID: | 20190201160800.7334-3-matwey.kornilov@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
This helper function makes spg_quad_inner_consistent() more readable when
changes from the next commit is introduced.
Signed-off-by: Matwey V. Kornilov <matwey(dot)kornilov(at)gmail(dot)com>
---
src/backend/access/spgist/spgquadtreeproc.c | 63 ++++++++++++++---------------
1 file changed, 31 insertions(+), 32 deletions(-)
diff --git a/src/backend/access/spgist/spgquadtreeproc.c b/src/backend/access/spgist/spgquadtreeproc.c
index f2e980b758..4904dbbe7b 100644
--- a/src/backend/access/spgist/spgquadtreeproc.c
+++ b/src/backend/access/spgist/spgquadtreeproc.c
@@ -112,6 +112,36 @@ getQuadrantArea(BOX *bbox, Point *centroid, int quadrant)
return result;
}
+static int spg_quad_inner_consistent_box_helper(ScanKey sk, Point *centroid)
+{
+ /*
+ * For this operator, the query is a box not a point. We
+ * cheat to the extent of assuming that DatumGetPointP won't
+ * do anything that would be bad for a pointer-to-box.
+ */
+ BOX *boxQuery = DatumGetBoxP(sk->sk_argument);
+ Point p;
+ int r = 0;
+
+ if (DatumGetBool(DirectFunctionCall2(box_contain_pt, PointerGetDatum(boxQuery), PointerGetDatum(centroid))))
+ {
+ /* centroid is in box, so all quadrants are OK */
+ return (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4);
+ }
+
+ /* identify quadrant(s) containing all corners of box */
+ p = boxQuery->low;
+ r |= 1 << getQuadrant(centroid, &p);
+ p.y = boxQuery->high.y;
+ r |= 1 << getQuadrant(centroid, &p);
+ p = boxQuery->high;
+ r |= 1 << getQuadrant(centroid, &p);
+ p.x = boxQuery->low.x;
+ r |= 1 << getQuadrant(centroid, &p);
+
+ return r;
+}
+
Datum
spg_quad_choose(PG_FUNCTION_ARGS)
{
@@ -302,7 +332,6 @@ spg_quad_inner_consistent(PG_FUNCTION_ARGS)
{
const ScanKey sk = in->scankeys + i;
Point *query = DatumGetPointP(sk->sk_argument);
- BOX *boxQuery;
switch (sk->sk_strategy)
{
@@ -326,37 +355,7 @@ spg_quad_inner_consistent(PG_FUNCTION_ARGS)
which &= (1 << 1) | (1 << 4);
break;
case RTContainedByStrategyNumber:
-
- /*
- * For this operator, the query is a box not a point. We
- * cheat to the extent of assuming that DatumGetPointP won't
- * do anything that would be bad for a pointer-to-box.
- */
- boxQuery = DatumGetBoxP(sk->sk_argument);
-
- if (DatumGetBool(DirectFunctionCall2(box_contain_pt,
- PointerGetDatum(boxQuery),
- PointerGetDatum(centroid))))
- {
- /* centroid is in box, so all quadrants are OK */
- }
- else
- {
- /* identify quadrant(s) containing all corners of box */
- Point p;
- int r = 0;
-
- p = boxQuery->low;
- r |= 1 << getQuadrant(centroid, &p);
- p.y = boxQuery->high.y;
- r |= 1 << getQuadrant(centroid, &p);
- p = boxQuery->high;
- r |= 1 << getQuadrant(centroid, &p);
- p.x = boxQuery->low.x;
- r |= 1 << getQuadrant(centroid, &p);
-
- which &= r;
- }
+ which &= spg_quad_inner_consistent_box_helper(sk, centroid);
break;
default:
elog(ERROR, "unrecognized strategy number: %d", sk->sk_strategy);
--
2.13.7
From | Date | Subject | |
---|---|---|---|
Next Message | Matwey V. Kornilov | 2019-02-01 16:08:00 | [PATCH 3/3] Add initial support for spgist quadtree @<(point,circle) operator |
Previous Message | Matwey V. Kornilov | 2019-02-01 16:07:58 | [PATCH 1/3] Introduce helper variable in spgquadtreeproc.c |