Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KNN support for spoints #116

Merged
merged 2 commits into from
Dec 22, 2023
Merged

KNN support for spoints #116

merged 2 commits into from
Dec 22, 2023

Conversation

vitcpp
Copy link
Contributor

@vitcpp vitcpp commented Dec 12, 2023

This is the original patch for review and improvement.

doc/indices.sgm Outdated
@@ -68,6 +68,11 @@
</para>
</listitem>
</itemizedlist>
<para>
GiST index can be used also for fast finding points closest to the given one
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change "fast finding points" to "quickly finding the points".

doc/indices.sgm Outdated
<para>
GiST index can be used also for fast finding points closest to the given one
when ordering by an expression with the <literal>&lt;-&gt;</literal> operator
is used, as shown in an example below.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove "is used" and move the comma to be at the end of "operator" on the previous line.

doc/indices.sgm Outdated
@@ -100,7 +112,6 @@
<![CDATA[CREATE INDEX test_pos_idx USING BRIN ON test (pos) WITH (pages_per_range = 16);]]>
</programlisting>
</example>

Copy link
Contributor

@esabol esabol Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the other </sect1> tags I saw, I don't think this blank line before </sect1> should have been removed.

CREATE FUNCTION g_spoint_consistent(internal, internal, int4, oid, internal)
RETURNS internal
AS 'MODULE_PATHNAME', 'g_spoint_consistent'
LANGUAGE 'c';

CREATE FUNCTION g_spoint_distance(internal, spoint, smallint, oid, internal)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create an upgrade script and add this function to it.

pgs_gist.sql.in Outdated
@@ -114,6 +117,7 @@ CREATE OPERATOR CLASS spoint
OPERATOR 14 @ (spoint, spoly),
OPERATOR 15 @ (spoint, sellipse),
OPERATOR 16 @ (spoint, sbox),
OPERATOR 17 <-> (spoint, spoint) FOR ORDER BY float_ops,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace doesn't match the other OPERATOR lines surrounding this addition. The 17 should line up with the 16 on the previous line for starters.

src/gist.c Outdated
@@ -681,6 +682,10 @@ g_spoint3_consistent(PG_FUNCTION_ARGS)
PG_RETURN_BOOL(false);
}

static double distance_vector_point_3d (Vector3D* v, double x, double y, double z) {
return acos ( (v->x * x + v->y * y + v->z * z) / sqrt( x*x + y*y + z*z ) ); // as v has length=1 by design
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the space after acos.

src/gist.c Outdated
v_high.y = (double)box->high.coord[1] / MAXCVALUE;
v_high.z = (double)box->high.coord[2] / MAXCVALUE;
// a box splits space into 27 subspaces (6+12+8+1) with different distance calculation
if(v_point.x < v_low.x) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change if( to if ( throughout this function in order to match the coding style of pgsphere.

src/gist.c Outdated
if(v_point.x < v_low.x) {
if(v_point.y < v_low.y) {
if(v_point.z < v_low.z) {
retval = distance_vector_point_3d (&v_point, v_low.x, v_low.y, v_low.z); //point2point distance
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change distance_vector_point_3d ( to distance_vector_point_3d( throughout this function in order to match the coding style of pgsphere.

@@ -1672,6 +1677,127 @@ fallbackSplit(Box3D *boxes, OffsetNumber maxoff, GIST_SPLITVEC *v)
v->spl_ldatum_exists = v->spl_rdatum_exists = false;
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An extra blank line doesn't need to be added here.

src/gist.c Outdated
PG_RETURN_FLOAT8(retval);
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two too many blank lines added here, I think.

@vitcpp
Copy link
Contributor Author

vitcpp commented Dec 12, 2023

I used pgindent to reformat new functions in gist.c.

Copy link
Contributor

@esabol esabol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple more very minor changes to the documentation, please.

Still needs an upgrade script. And maybe a version bump?

doc/indices.sgm Outdated
@@ -68,6 +68,11 @@
</para>
</listitem>
</itemizedlist>
<para>
GiST index can be also used for quickly finding the points closest to the given one
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change GiST index to A GiST index. Sorry should have caught that in my previous review.

doc/indices.sgm Outdated
@@ -82,6 +87,13 @@
<![CDATA[CREATE INDEX test_pos_idx ON test USING GIST (pos);]]>
<![CDATA[VACUUM ANALYZE test;]]>
</programlisting>
<para>
To find points closest to a given spherical position, use the <literal>&lt;-&gt;</literal> operator:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change To find points to To find the points.

@@ -0,0 +1,16 @@
-- Upgrade: 1.4.2 -> 1.5.0

CREATE FUNCTION g_spoint_distance(internal, spoint, smallint, oid, internal)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use CREATE OR REPLACE in the upgrade script? See issue #111.

Copy link
Contributor

@esabol esabol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Raise the version up to 1.5.0, add upgrade script

Fix issues found after the review
@vitcpp
Copy link
Contributor Author

vitcpp commented Dec 20, 2023

Squashed latest 3 commits. The two commits are kept - the original commit and the commit with code adjustment.

@vitcpp vitcpp merged commit f20a664 into postgrespro:master Dec 22, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants