<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<font face="Ubuntu">Hello Rémi,<br>
<br>
The function you refer to<br>
<a class="moz-txt-link-freetext" href="https://github.com/qgis/QGIS/blob/master/src/core/vector/qgsvectorlayerfeaturecounter.cpp#L76-L90">https://github.com/qgis/QGIS/blob/master/src/core/vector/qgsvectorlayerfeaturecounter.cpp#L76-L90</a><br>
is only called when the feature count must be done for the symbols
(for instance when a categorized symbology is used, then QGIS does
not use estimated metadata, and the count for each symbol is then
evaluated and displayed).<br>
<br>
Normally there is no SELECT count(*) FROM or SELECT * FROM when
estimated metadata is used.<br>
<br>
Regards,<br>
</font><font face="Ubuntu"><br>
</font>
<pre class="moz-signature" cols="72">--
Jacky Volpes
Ingénieur SIG - Oslandia</pre>
<div class="moz-cite-prefix"><br>
Le 26/06/2022 à 20:20, Rémi Desgrange via QGIS-Developer a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:MRXP264MB0261BE45B9A0BEB870847B16F3B69@MRXP264MB0261.FRAP264.PROD.OUTLOOK.COM">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style>@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}@font-face
{font-family:Lato;
panose-1:2 15 5 2 2 2 4 3 2 3;}p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:10.0pt;
font-family:"Calibri",sans-serif;}a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}div.WordSection1
{page:WordSection1;}</style>
<div class="WordSection1">
<p class="MsoNormal"><span
style="font-size:11.0pt;mso-fareast-language:EN-US"
lang="FR">Thanks Regis.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;mso-fareast-language:EN-US"
lang="FR"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;mso-fareast-language:EN-US"
lang="EN-US">I tried with an existing project, and with no
project. The information of the layers is:<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;mso-fareast-language:EN-US"
lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Lato",sans-serif;color:black">service='</span><span
style="font-family:"Lato",sans-serif;color:black"
lang="EN-US">mycomp_prod</span><span
style="font-family:"Lato",sans-serif;color:black">'
sslmode=require key='gid' estimatedmetadata=true srid=27572
type=Point checkPrimaryKeyUnicity='1' table="public"."</span><span
style="font-family:"Lato",sans-serif;color:black"
lang="EN-US">mylayer</span><span
style="font-family:"Lato",sans-serif;color:black">"<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Lato",sans-serif;color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Lato",sans-serif;color:black"
lang="EN-US">with service in `.pg_service.conf` :<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Lato",sans-serif;color:black"
lang="EN-US">[mycomp_prod]<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Lato",sans-serif;color:black"
lang="EN-US">user=rd<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Lato",sans-serif;color:black"
lang="EN-US">sslmode=require<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Lato",sans-serif;color:black"
lang="EN-US">host=gis.mycomp.fr<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Lato",sans-serif;color:black"
lang="EN-US">port=5432<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Lato",sans-serif;color:black"
lang="EN-US">dbname=mycomp<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Lato",sans-serif;color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Lato",sans-serif;color:black"
lang="EN-US">(don’t blame me for the 27572 OK
</span><span style="font-family:"Apple Color
Emoji";color:black" lang="EN-US">😅</span><span
style="font-family:"Lato",sans-serif;color:black"
lang="EN-US">)<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Lato",sans-serif;color:black"
lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Lato",sans-serif;color:black"
lang="EN-US">I think I’ll open an issue because it _<i>seems</i>_
to do a SELECT count(*) FROM mylayer + SELECT * FROM mylayer
until all features have been fetched. In my example, I have
a 11M Points layer so it takes a while </span><span
style="font-family:"Apple Color
Emoji";color:black" lang="EN-US">😊</span><span
style="font-family:"Lato",sans-serif;color:black"
lang="EN-US">.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div style="border:none;border-top:solid #B5C4DF
1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span
style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">Régis
Haubourg <a class="moz-txt-link-rfc2396E" href="mailto:regis.haubourg@gmail.com"><regis.haubourg@gmail.com></a><br>
<b>Date: </b>Saturday, 25 June 2022 at 12:54<br>
<b>To: </b>Rémi Desgrange <a class="moz-txt-link-rfc2396E" href="mailto:remi.desgrange@ielo.net"><remi.desgrange@ielo.net></a><br>
<b>Cc: </b>QGIS Developers List
<a class="moz-txt-link-rfc2396E" href="mailto:qgis-developer@lists.osgeo.org"><qgis-developer@lists.osgeo.org></a><br>
<b>Subject: </b>Re: [QGIS-Developer] Feature count for DB
provider.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">Hi Rémy,
There had been a lot of work for postGIS and oracle
providers. A count(*) might be really expensive for big
tables, so there are options to use db statistics instead
of real count. I bet the loop you point out occurs only in
fallback situations but is not the main case.<o:p></o:p></span></p>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">One is
here for instance by there are numerous PRs like this
one
<a href="https://github.com/qgis/QGIS/pull/37619"
moz-do-not-send="true" class="moz-txt-link-freetext">https://github.com/qgis/QGIS/pull/37619</a><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">In think
@troopa81 has a clear view of the current state.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">all the
best<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">Régis <o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">Le sam.
25 juin 2022 à 10:38, Rémi Desgrange via QGIS-Developer
<<a href="mailto:qgis-developer@lists.osgeo.org"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">qgis-developer@lists.osgeo.org</a>>
a écrit :<o:p></o:p></span></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC
1.0pt;padding:0cm 0cm 0cm
6.0pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:11.0pt" lang="FR">Hi,</span><span
style="font-size:11.0pt"><o:p></o:p></span></p>
<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:11.0pt" lang="FR"> </span><span
style="font-size:11.0pt"><o:p></o:p></span></p>
<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:11.0pt" lang="EN-US">Just launched
the new QGIS 3.24, and tests the SQL debugger, I
just found out that the “feature count” does a while
loop on all features in the layer to count.</span><span
style="font-size:11.0pt"><o:p></o:p></span></p>
<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:11.0pt" lang="EN-US"> </span><span
style="font-size:11.0pt"><o:p></o:p></span></p>
<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:11.0pt" lang="EN-US">While it’s
probably necessary for shapefiles or stuff like
that, it appears suboptimal for databases access. I
found this part in the code that looks like to be
responsible for the feature counts, <a
href="https://github.com/qgis/QGIS/blob/master/src/core/vector/qgsvectorlayerfeaturecounter.cpp#L76-L90"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">
https://github.com/qgis/QGIS/blob/master/src/core/vector/qgsvectorlayerfeaturecounter.cpp#L76-L90</a>
</span><span style="font-size:11.0pt"><o:p></o:p></span></p>
<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:11.0pt" lang="EN-US"> </span><span
style="font-size:11.0pt"><o:p></o:p></span></p>
<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:11.0pt" lang="EN-US">Do you think I
could make a special case for database-based
provider (geopackage, postgres/oracle/mysql/etc…)
that launch a “SELECT count(*) FROM table” instead
of looping on all features.</span><span
style="font-size:11.0pt"><o:p></o:p></span></p>
<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:11.0pt" lang="EN-US"> </span><span
style="font-size:11.0pt"><o:p></o:p></span></p>
<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:11.0pt" lang="EN-US">Thanks.
</span><span style="font-size:11.0pt"><o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><span style="font-size:11.0pt">_______________________________________________<br>
QGIS-Developer mailing list<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">QGIS-Developer@lists.osgeo.org</a><br>
List info: <a
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">
https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
Unsubscribe: <a
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">
https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><o:p></o:p></span></p>
</blockquote>
</div>
</div>
<br>
<fieldset class="moz-mime-attachment-header"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
QGIS-Developer mailing list
<a class="moz-txt-link-abbreviated" href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.osgeo.org</a>
List info: <a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/qgis-developer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
Unsubscribe: <a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/qgis-developer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
</pre>
</blockquote>
<br>
</body>
</html>