{"id":755,"date":"2011-05-06T20:20:56","date_gmt":"2011-05-07T01:20:56","guid":{"rendered":"http:\/\/anvil-of-time.com\/wordpress\/?p=755"},"modified":"2021-03-10T20:13:10","modified_gmt":"2021-03-11T01:13:10","slug":"powerbuilder-filter-vs-find-performance","status":"publish","type":"post","link":"https:\/\/anvil-of-time.com\/powerbuilder\/powerbuilder-filter-vs-find-performance\/","title":{"rendered":"PowerBuilder &#8211; Filter vs Find performance"},"content":{"rendered":"<p>If you have rows in a datawindow\/datastore and you want to look through them for a match against some new code (say you are looking for an existing entry so you can add to the quantity), it is better to use the Find method in a loop than to use the Filter method.<\/p>\n<p>Filtering large sets of data causes the movement said data from the Primary to the Filter buffer which takes more time than finding a single row. If the initial selection of the data was limited (WHERE clause or JOINS) then there wouldn&#8217;t be much difference (and you wouldn&#8217;t be sucking all the extra data back to the client either).<\/p>\n<p>If you are dealing with data displayed to the user you have a new set of issues with Filter including triggering of RowFocusChanged, loss of selected row if it&#8217;s filtered out, display &#8216;jumping\/flicker&#8217;, etc.<\/p>\n<p>An interesting take on this can be found in the <a href=\"https:\/\/groups.google.com\/forum\/?fromgroups#!topic\/powersoft.public.powerbuilder.datawindow\/U9yg6IqB96U\" target=\"_blank\" rel=\"noopener\">following posts from 1999<\/a>.<\/p>\n<p>No Good<\/p>\n<pre name=\"code\" class=\"VB\">FOR ll_i = 1 TO dw_A.Rowcount()\n\tls_code = dw_A.Getitemstring(ll_i,&#039;code_column&#039;)\n\tls_filter = &quot;this_code = &#039;&quot; + ls_code + &quot;&#039;&quot;\n\tdw_B.Setfilter(ls_filter)\n\tdw_B.Filter() \/\/ hits the database each time\n\tFOR ll_j = 1 to dw_B.Rowcount()\n\t\tll_quantity += dw_B.Getitemnumber(ll_j,&#039;this_quantity&#039;)\n\tNEXT\nNEXT<\/pre>\n<p>Good<\/p>\n<pre name=\"code\" class=\"VB\">FOR ll_i = 1 TO dw_A.Rowcount()\n\tls_code = dw_A.Getitemstring(ll_i,&#039;code_column&#039;)\n\tls_find = &quot;this_code = &#039;&quot; + ls_code + &quot;&#039;&quot;\n\tll_foundrow = dw_B.Find(ls_find, 1, dw_B.Rowcount() + 1)\n\tDO WHILE ll_foundrow &gt; 0\n\t\tll_quantity += dw_B.Getitemnumber(ll_foundrow,&#039;this_quantity&#039;)\n\t\tll_foundrow = dw_B.Find(ls_find, ll_foundrow + 1, dw_B.Rowcount() + 1)\n\tLOOP\nNEXT<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you have rows in a datawindow\/datastore and you want to look through them for a match against some new code (say you are looking for an existing entry so you can add to the quantity), it is better to use the Find method in a loop than to use the Filter method. Filtering large&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,10],"tags":[12,16],"_links":{"self":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/755"}],"collection":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/comments?post=755"}],"version-history":[{"count":7,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/755\/revisions"}],"predecessor-version":[{"id":1944,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/755\/revisions\/1944"}],"wp:attachment":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/media?parent=755"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/categories?post=755"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/tags?post=755"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}