Hi Andrea, hi Jody, Thanks for your responses and insights.
Looking at the SQLServerDialect class, I understand the reasons for blocking search hints on virtual tables. Unlike in SQL Server, hints can only be added at the very end of a query or subquery in HANA. For example, it is not possible to put a hint after a table name in a query as long as other query elements appear after the table name (like ORDER BY or GROUP BY), i.e. -- Okay SELECT col1, SUM(val1) FROM tab GROUP BY col1 WITH HINT(MAX_CONCURRENCY(1)) -- Not okay SELECT col1, SUM(val1) FROM tab WITH HINT(MAX_CONCURRENCY(1)) GROUP BY col1 In Hana, it's always okay to append a hint at the end of the query. The motivation to add hints to GeoServer view queries is described in https://stackoverflow.com/questions/73647691/how-to-add-sql-hints-to-geoserver-layers. The OP wants to add hints for the HANA optimizer. He can add the hint to the query he enters in GeoServer: select ID,DISTRICT_ID,DISTRICT_NAME,GEOLOC FROM MG_SPATIAL.V_GIS_DISTRICT WITH HINT OPTIMIZATION_LEVEL (RULE_BASED) But then the hint is only applied to the subquery when the actual query is generated: SELECT "ID","DISTRICT_ID","DISTRICT_NAME","GEOLOC".ST_AsBinary() as "GEOLOC" FROM (select ID,DISTRICT_ID,DISTRICT_NAME,GEOLOC FROM MG_SPATIAL.V_GIS_DISTRICT WITH HINT OPTIMIZATION_LEVEL (RULE_BASED) ) as "vtable" WHERE "GEOLOC".ST_IntersectsRectPlanar(ST_GeomFromWKB(?, 3067), ST_GeomFromWKB(?, 3067)) = 1 LIMIT 1000000 OFFSET 0 As a result, the optimizer applies the hint only to the subquery, but not on the whole query. What the OP would like to achieve is the following query: SELECT "ID","DISTRICT_ID","DISTRICT_NAME","GEOLOC".ST_AsBinary() as "GEOLOC" FROM (select ID,DISTRICT_ID,DISTRICT_NAME,GEOLOC FROM MG_SPATIAL.V_GIS_DISTRICT ) as "vtable" WHERE "GEOLOC".ST_IntersectsRectPlanar(ST_GeomFromWKB(?, 3067), ST_GeomFromWKB(?, 3067)) = 1 LIMIT 1000000 OFFSET 0 WITH HINT OPTIMIZATION_LEVEL (RULE_BASED) Hence, it would be great if a SQLDialect could decide itself whether it wants to add hints to a query with an embedded VirtualTable query. If you don't have objections, I'd like to add a way to let the SQLDialect decide. However, I'm not sure what the best way would be. I considered the following options: 1. Ask the SQLDialect via a method whether hints should be added, e.g. boolean handleSelectHintsOnVirtualTableQueries() returning false by default. 2. Add a new method to add "general" hints independent of the query type, e.g. handleGeneralHints(SimpleFeatureType featureType, Query query, StringBuffer sql), doing nothing by default. 3. Pass along the information on the type of query to handleSelectHints(). That would be an incompatible change though. Maybe overloading the method would be an option. Maybe you have better ideas. What do you think? Thanks and best regards, Stefan From: Andrea Aime <andrea.a...@geosolutionsgroup.com> Sent: Wednesday, December 14, 2022 10:20 AM To: Uhrig, Stefan <stefan.uh...@sap.com> Cc: GeoTools <geotools-devel@lists.sourceforge.net> Subject: Re: [Geotools-devel] JDBCDataStore blocks search hints on virtual tables HI Stefan, a virtual table can be built around any resultset returning statement (e.g., a stored procedure), and the JDBCDataStore machinery makes no attempt to understand the SQL being provided, it just uses it as a subquery in the from clause. Query hints, at least in the databases that I'm familiar with, must be provided in very specific positions, which requires an understanding of the SQL involved. If you check the SQLServerDialect handleSelectHints, it makes assumptions on how the query is built to find the exact point where a hint can be added (it's pretty much added mid-query). The assumption is fair because we control how a select against a table is built, the same cannot be said for virtual tables, where anything goes in the user provided query (a table might not be involved at all). Is SAP HANA so freeform that one can put query hints pretty much anywhere, regardless of what is found in the user provided query? Even if it was, you'd have to modify the API to allow other database (SQLServer) to tell apart actual table vs virtual table. Cheers Andrea On Tue, Dec 13, 2022 at 9:36 PM Uhrig, Stefan via GeoTools-Devel <geotools-devel@lists.sourceforge.net<mailto:geotools-devel@lists.sourceforge.net>> wrote: Hi all, Recently, a group of GeoServer users on HANA requested the possibility to append hints to SQL queries. Luckily, there was already SQLDialect#handleSelectHints(). So, I could just override the method in HanaDialect and append the hints to the query, which I did in [GEOT-7230] (https://github.com/geotools/geotools/pull/4064<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fgeotools%2Fgeotools%2Fpull%2F4064&data=05%7C01%7Cstefan.uhrig%40sap.com%7Cb28354be92e248229e1008daddb458d3%7C42f7676cf455423c82f6dc2d99791af7%7C0%7C0%7C638066063899188001%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=eUhZyU25GJOJzzUHhbzijLhY72qNfYNgXSpv3U%2FwE1s%3D&reserved=0>). Now the group of users who requested the feature noticed that it works for common GeoServer layers, but not for GeoServer views, which are based on GeoTools' VirtualTable. I investigated and found that JDBCDataStore deliberately blocks the addition of search hints (https://github.com/geotools/geotools/blob/29394a11ce3128a625f5251abeb9b0b09cc0105b/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStore.java#L3505<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fgeotools%2Fgeotools%2Fblob%2F29394a11ce3128a625f5251abeb9b0b09cc0105b%2Fmodules%2Flibrary%2Fjdbc%2Fsrc%2Fmain%2Fjava%2Forg%2Fgeotools%2Fjdbc%2FJDBCDataStore.java%23L3505&data=05%7C01%7Cstefan.uhrig%40sap.com%7Cb28354be92e248229e1008daddb458d3%7C42f7676cf455423c82f6dc2d99791af7%7C0%7C0%7C638066063899188001%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=sVHaKj8P8AttYUGJSQbrHOwhlb1EugMm3iZEYYXtMJM%3D&reserved=0>). I found that the SQLDialect#handleSelectHints() has been introduced with "[GEOT-4707] Add a flag to force spatial index usage in sql server" (https://github.com/geotools/geotools/pull/371/files<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fgeotools%2Fgeotools%2Fpull%2F371%2Ffiles&data=05%7C01%7Cstefan.uhrig%40sap.com%7Cb28354be92e248229e1008daddb458d3%7C42f7676cf455423c82f6dc2d99791af7%7C0%7C0%7C638066063899188001%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=hb5rgW0tRJ2jmEIMfFKwOGjlS0B72wx%2Ff5Eno2GNkO4%3D&reserved=0>). Adding search hints to VirtualTable queries was blocked from the start. Does someone know why search hints are not added to VirtualTable queries? In the HANA use case, I could not identify any reason yet why the addition of search hints should be blocked. I might oversee something though. If there is no urgent reason to block search hints in VirtualTable queries, what would be a good way to support search hints on VirtualTable queries in a SQLDialect? Would the introduction of an additional function like appendSearchHintsToVirtualTableQueries() be acceptable? Thank you and best regards, Stefan _______________________________________________ GeoTools-Devel mailing list GeoTools-Devel@lists.sourceforge.net<mailto:GeoTools-Devel@lists.sourceforge.net> https://lists.sourceforge.net/lists/listinfo/geotools-devel<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.sourceforge.net%2Flists%2Flistinfo%2Fgeotools-devel&data=05%7C01%7Cstefan.uhrig%40sap.com%7Cb28354be92e248229e1008daddb458d3%7C42f7676cf455423c82f6dc2d99791af7%7C0%7C0%7C638066063899188001%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=GpxdcbXvdbtgS3MDFqC0feJPlU%2FTwdQpit%2Fttpvc2DA%3D&reserved=0> -- Regards, Andrea Aime == GeoServer Professional Services from the experts! Visit http://bit.ly/gs-services-us<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fbit.ly%2Fgs-services-us&data=05%7C01%7Cstefan.uhrig%40sap.com%7Cb28354be92e248229e1008daddb458d3%7C42f7676cf455423c82f6dc2d99791af7%7C0%7C0%7C638066063899188001%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=STdbVKVvrR4uR6OYDoqdZnywwv1yYn25S0Vhn3hX3Ds%3D&reserved=0> for more information. == Ing. Andrea Aime @geowolf Technical Lead GeoSolutions Group phone: +39 0584 962313 fax: +39 0584 1660272 mob: +39 339 8844549 https://www.geosolutionsgroup.com/<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.geosolutionsgroup.com%2F&data=05%7C01%7Cstefan.uhrig%40sap.com%7Cb28354be92e248229e1008daddb458d3%7C42f7676cf455423c82f6dc2d99791af7%7C0%7C0%7C638066063899188001%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=9LlK4FpXx7zjZD9i3zjldAJa%2FdYc1I7GQ02rduimoJI%3D&reserved=0> http://twitter.com/geosolutions_it<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Ftwitter.com%2Fgeosolutions_it&data=05%7C01%7Cstefan.uhrig%40sap.com%7Cb28354be92e248229e1008daddb458d3%7C42f7676cf455423c82f6dc2d99791af7%7C0%7C0%7C638066063899188001%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=6sSuJBotjotg%2BoDyUBgAJG13Nu0%2FX6JtLHIigymxcUA%3D&reserved=0> ------------------------------------------------------- Con riferimento alla normativa sul trattamento dei dati personali (Reg. UE 2016/679 - Regolamento generale sulla protezione dei dati "GDPR"), si precisa che ogni circostanza inerente alla presente email (il suo contenuto, gli eventuali allegati, etc.) è un dato la cui conoscenza è riservata al/i solo/i destinatario/i indicati dallo scrivente. Se il messaggio Le è giunto per errore, è tenuta/o a cancellarlo, ogni altra operazione è illecita. Le sarei comunque grato se potesse darmene notizia. This email is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. We remind that - as provided by European Regulation 2016/679 "GDPR" - copying, dissemination or use of this e-mail or the information herein by anyone other than the intended recipient is prohibited. If you have received this email by mistake, please notify us immediately by telephone or e-mail
_______________________________________________ GeoTools-Devel mailing list GeoTools-Devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-devel