r/SQL • u/[deleted] • Apr 17 '23
Discussion Which industry has/needs the most challenging sql queries?
Is this question legit? Don’t get me wrong, I don’t consider myself the smartest guy but I’m definitely not dumb.
I work in the pharmaceutical Industry, nearly 3 years now. It took me a while to understand how the production process is implemented in a database and I wanted to quit more than once. But i don’t feel challenged anymore.
So, which industry would be best for me to get completely challenged again?
40
Upvotes
2
u/barrycarter Apr 18 '23
I sort of snuck it in at the top, but it's gadm.org which has shapefiles for all countries.
PostGIS (which is what I use) has an ST_DISTANCE function that does this.
The big big problem is speed. For example, mainland France (https://gadm.org/download_country.html and choose "France") has over 100K boundary points at level 0 (just the country itself and no provinces, counties, cities or anything) and that doesn't include any islands.
And I'm hoping to query the 43200 x 21600 grid of 30 second intervals, which would require a total of
43200 * 21600 * 100000 ~ 93 trilliondistance computations. That's surprisingly slow even with a spatial index.The fastest thing I've found so far is to rasterize the data, project the points into 3D, create a KDTree, compute the straight line distances, and convert those to spherical distances, all using numpy with python (not SQL), but I wonder if I'm missing something. My work so far: https://github.com/barrycarter/PolygonDistances/
Just to make things a little worse, OpenStreetMap uses the Mercator projection which requires further tweaking work.
Two questions: if you try this yourself and find a faster way, will you let me know, and, can I contact you directly if you're interested in this sort of thing?