[gdal-dev] Ogr: Difference betwen SQLexectue() and SetAttributFilter() ?

Even Rouault even.rouault at mines-paris.org
Mon Jul 23 03:11:26 PDT 2012


Le lundi 23 juillet 2012 11:19:48, Benjamin a écrit :
> Hi,
> 
> There is a difference betwen :
> 
> layer = ds.ExecuteSQL("SELECT * FROM MY_TABLE WHERE ID='my_id'", null, "");
> 
> And
> 
> layer = ds.GetLayerByName("MY_TABLE");
> layer.SetAttributeFilter("ID='my_id'");
> 
> ?

Short answer:

Generally, there should not be a visible difference between both syntax. There 
might be very subtle performance differences due to internal implementation 
details, but I doubt you could notice them. So use the one that is the most 
convenient for you.


Long answer :

For drivers that are not based on relational database manager, such as 
Shapefile, in both cases, the filter will be evaluated on "client-side" (there 
is no server side ;-))

For drivers such as PG, MySQL, SQLite, etc, the ExecuteSQL() is directly 
transfered to the database engine. But the SetAttributeFilter() is also used 
to synthetize a "SELECT * FROM the_table WHERE the_attribute_filter" 
internally, that is transfered to the database engine, so the performance will 
also be good.


More information about the gdal-dev mailing list