Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Hash opclass for spoint#102

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

df7cb
Copy link
Contributor

Besides hash indexes on spoint, this enables "select distinct spoint from tbl" queries.

Close#101.

Copy link
Contributor

@esabolesabol left a comment

Choose a reason for hiding this comment

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

Fantastic contribution! Thank you,@df7cb !

I think the only thing missing is the addition of the pgs_hash.sql.in to the upgrade script?

@df7cb
Copy link
ContributorAuthor

That's already in there:

pg_sphere--1.3.1--1.3.2.sql: pgs_circle_sel.sql.in pgs_hash.sql.incat upgrade_scripts/$@.in $^ > $@

@esabol
Copy link
Contributor

That's already in there:

pg_sphere--1.3.1--1.3.2.sql: pgs_circle_sel.sql.in pgs_hash.sql.incat upgrade_scripts/$@.in $^ > $@

Oh, sorry, I was expecting to seepg_sphere--1.3.1--1.3.2.sql in the list of changed files in the commit and didn't look closely enough at the changes to theMakefile.

Copy link
Contributor

@esabolesabol left a comment

Choose a reason for hiding this comment

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

I will defer to@vitcpp when it comes to the implementation of the hash function, but everything else looks good to me.

df7cb reacted with thumbs up emoji
@df7cb
Copy link
ContributorAuthor

The current implementation just xor-s the 4x4 bytes chunks together. I think that should yield a good distribution on the "random" coordinate values that should be seen in practise. If we think that's not good enough, we might just use the built-in hash functions on floats. (hashfloat8,hashfloat8extended)

esabol reacted with thumbs up emoji

@vitcpp
Copy link
Contributor

I think, everythink is ok, but I would propose to improve the hash function. The longitude range is [0, 2*pi], the latitude range is [-pi/2,p/2], EPSILON = 1E-9. We have to calculate the hashes in these ranges. The smaller numbers are "equal" and should have the same hash. There are also some other special values like INF, NAN. I think that all NANs should produce the same hash value. Denormalized numbers are smaller than 1E-9, they are 0. I will think about some other implementation of hash function.

@df7cb
Copy link
ContributorAuthor

df7cb commentedNov 7, 2023
edited
Loading

I don't think we can do much about mapping values less than EPSILON apart to the same value - we don't know in which direction to round. The only thing we could do is map values close to 0 to 0, but if we don't do it for the rest, why bother with 0.

Infinity is not a problem since it's a unique bit value, but along with NaN, can these really appear in spoint values? I even had trouble getting-0 into an spoint - at one point I think I had one, but couldn't reproduce it later.

One possible hash implementation that takes care of-0 andNaN would be this:

PG_RETURN_INT32(hashfloat8(p1->lat + p1->lng));

or

PG_RETURN_INT32(hashfloat8(p1->lat) ^ hashfloat8(p1->lng));
vitcpp reacted with thumbs up emoji

@vitcpp
Copy link
Contributor

@df7cb May be to use hashfloat8? I have no strong arguments against your implementation except that it is not the best hash function, I think. I want to ask my junior colleagues to think how to improve hash function and benchmark it.

Besides hash indexes on spoint, this enables "select distinct spointfrom tbl" queries.Closepostgrespro#101.
@df7cb
Copy link
ContributorAuthor

I used thehash1 ^ hash2 approach now, and added documentation.

vitcpp reacted with thumbs up emoji

@vitcppvitcpp mentioned this pull requestNov 7, 2023
@vitcppvitcpp merged commit339ed93 intopostgrespro:masterNov 7, 2023
@df7cbdf7cb deleted the hash-opclass branchNovember 8, 2023 08:48
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@vitcppvitcppvitcpp approved these changes

@esabolesabolesabol approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Missing equality operator for type spoint?
3 participants
@df7cb@esabol@vitcpp

[8]ページ先頭

©2009-2025 Movatter.jp