That should be faster, unless Pro automatically switches to these when it detects that you are comparing points and polygons.
give it a try and see if it makes a difference performancewise.
Original Message:
Sent: 07-23-2024 02:03
From: Yong Zhang
Subject: Same query huge performance gaps between MapBasic and Python
Thank you Peter.
After adjusted the order of the two tables, in from and where statements, time cost by MapBasic reduced to the similar level as Python query.
------------------------------
Yong Zhang
Knowledge Community Shared Account
Burlington MA
Original Message:
Sent: 07-22-2024 12:07
From: Peter Møller
Subject: Same query huge performance gaps between MapBasic and Python
Hi
Can you check that the order of the two tables is the same in the two queries?
To me, it seems as if the order is reversed.
------------------------------
Peter Horsbøll Møller
Principal Presales Consultant | Distinguished Engineer
Precisely | Trust in Data
Original Message:
Sent: 07-22-2024 05:21
From: Yong Zhang
Subject: Same query huge performance gaps between MapBasic and Python
The situation I found is:
I have a query to calculate population for the network coverage, I have the pops points MapInfo tab file and the network coverage polygons.
I did the query in MapBasic windows:
Dim start as IntegerDim end_t as IntegerDim elapsed as Integerstart = Timer()Select AllSites_NR_C_ID_20240715.Transmitte, sum(PopEst_2021_Density) from GNAF_AUS_202005_EST2021, AllSites_NR_C_ID_20240715 where GNAF_AUS_202005_EST2021.Obj Intersects AllSites_NR_C_ID_20240715.Obj group by AllSites_NR_C_ID_20240715.Transmitte into nr_c_id_popsExport "nr_c_id_pops" Into "C:\Users\{username}\Documents\nr_c_id_pops_mapinfo.csv" Type "ASCII" Overwrite Delimiter "," TitlesClose Table nr_c_id_pops Interactiveend_t = Timer()elapsed = end_t - startprint "NR_C_ID time cost is: " + str$(elapsed)
and did the same query in Python:
import timeimport ostables = pro.Catalog.Tablestables_list = []# check if points table existstable_points = 'GNAF_AUS_202005_EST2021'for table in tables: tables_list.append(table.Alias)if table_points in tables_list: print('GNAF table has been opened!') tables_list.remove(table_points) else: print("GNAF table doesn't exist.") exit()home_path = os.path.expanduser("~")path = os.path.join(home_path, "Downloads")for table in tables_list: start_time = time.time() table_polygon = table table_pops = table + "_pops" file = table_pops + "_mapinfo_python.csv" file_name = os.path.join(path, file) do("Select {0}.Transmitte,sum({1}.PopEst_2021_Density) from {0}, {1} where {0}.Obj Intersects {1}.Obj into {2} group by {0}.Transmitte".format( table_polygon, table_points, table_pops)) do("Export {0} Into \"{1}\" Type \"ASCII\" Overwrite Delimiter \",\" Titles".format(table_pops, file_name)) do("Close Table {0} Interactive".format(table_pops)) end_time = time.time() execution_time = end_time - start_time formatted_exec_time = f'{execution_time:.2f}' print(table_pops + ' execution time is: ' + formatted_exec_time + ' seconds')
The results: it costed 330 seconds in MapBasic, while in Python just costed 84 seconds in average.
Any reasons behind it? I thought Python is calling MapBasic to do the query, the performance should be similar.
------------------------------
Yong Zhang
Knowledge Community Shared Account
Burlington MA
------------------------------