I'm trying to see if I can optimize the following query which was written by my predecessor:
SELECT tms.*, 0 as kyori , (power( (139.745069 - to_number(tms.lng,'000D00000000')) / 0.0111 * 1000000, 2) + power( (35.662978 - to_number(tms.lat,'000D00000000')) / 0.0091 *1000000, 2) ) AS kyori2 FROM ttb_members tms, mtb_tenshu mt WHERE (tms.tenshu_cd = mt.small_cd) AND (tms.view <> 0) AND (tms.type in (2,3)) AND (tms.delete_datetime is null) ORDER BY kyori2 ASC OFFSET 20 LIMIT 20
and I can't find any reference to the
tms.* listed in the very beginning. The query seems to run if I remove it so I can't figure out exactly why it's there. Further, later in the query in the
FROM line, there is
mtb_tensyu mt which I can't get what the
mt is. (For the record, 'kyori' in Japanese means 'distance').
I've Googled this and looked thoroughly at the PostgreSQL documents, but I can't find what these are referencing. Any help would be greatly appreciated.