{"id":112830,"date":"2026-11-04T07:00:00","date_gmt":"2026-11-04T15:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=112830"},"modified":"2026-11-05T09:27:24","modified_gmt":"2026-11-05T17:27:24","slug":"20261104-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20261104-00\/?p=112830\/","title":{"rendered":"There are things with ranks, but it&#8217;s not always clear what the ranks mean"},"content":{"rendered":"<p>There are a number of features in Windows that establish an order by a thing called a &#8220;rank&#8221;. Unfortunately, the documentation for them doesn&#8217;t always tell you what rank actually means. Does a higher rank take priority over a lower rank?<\/p>\n<p>I started with SQL Server. In the documentation page <a title=\"Limit search results with RANK\" href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/search\/limit-search-results-with-rank?view=sql-server-ver17#:~:text=with%20a%20lower%20value,lower%20relevance\"> Limit search results with RANK<\/a>, it opens by telling you that higher ranks mean better matches, or at least that lower ranks mean worse matches, which is basically the same thing:<\/p>\n<blockquote class=\"q\"><p>The CONTAINSTABLE and FREETEXTTABLE functions return a column named RANK that contains ordinal values from 0 through 1,000 (rank values). These values rank the rows according to how well they match the selection criteria. The rank values indicate only a relative order of relevance of the rows in the result set, <span style=\"border: solid 1px currentcolor;\">with a lower value indicating lower relevance<\/span>. The actual values are unimportant and typically differ each time the query runs.<\/p><\/blockquote>\n<p>It says that lower ranks are poorer-quality matches, so this implies that higher quality matches have higher ranks.<\/p>\n<p>This &#8220;higher is better&#8221; is made more explicitly on the the RANK of a query result is a value that increases as the match quality improves: <a title=\"Query with Full-Text Search\" href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/search\/query-with-full-text-search?view=sql-server-ver17#:~:text=The%20higher%20the%20rank,full%2dtext%20query.\"> Query with Full-Text Search<\/a> page:<\/p>\n<blockquote class=\"q\"><p>The higher the rank value of the text or document in a row, the more relevant the row is for the given full-text query.<\/p><\/blockquote>\n<p>Okay, so that&#8217;s SQL Server. Good job, SQL Server.<\/p>\n<p>The Windows Package Graph also has the concept of rank. And here the documentation is less helpful.<\/p>\n<p>The <i>rank<\/i> parameter to the <code>Add\u00adPackage\u00adDependency<\/code> function <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/appmodel\/nf-appmodel-addpackagedependency#:~:text=The%20rank%20to%20use,the%20remarks.\"> is documented as<\/a><\/p>\n<blockquote class=\"q\"><p>The rank to use to add the resolved package to the caller&#8217;s package graph. For more information, see the remarks.<\/p><\/blockquote>\n<p>If you go down to the remarks, <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/appmodel\/nf-appmodel-addpackagedependency#:~:text=If%20multiple%20packages%20are%20present,options%20parameter.\"> the only mention of rank<\/a> is<\/p>\n<blockquote class=\"q\"><p>If multiple packages are present in the package graph with the same rank as the call to <b>Add\u00adPackage\u00adDependency<\/b>, the resolved package is (by default) added after others of the same rank. To add a package before others of the same rank, specify <code>Add\u00adPackage\u00adDependency\u00adOptions_<wbr \/>Prepend\u00adIf\u00adRank\u00adCollision<\/code> for the options parameter.<\/p><\/blockquote>\n<p>That&#8217;s nice, but it doesn&#8217;t tell me whether packages are searched from low rank to high, or from high rank to low. All I know is that if I want to be considered ahead of others of the <i>same<\/i> rank, I should pass this special flag; otherwise by default I am considered <i>after<\/i> others of the same rank. But it doesn&#8217;t say whether I am considered ahead of or after other packages with <i>different<\/i> ranks.<\/p>\n<p>There is a &#8220;For more information&#8221; that takes me to the <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/apps\/desktop\/modernize\/framework-packages\/use-the-dynamic-dependency-api#:~:text=and%20the%20desired%20rank,graph.\"> Using the Dynamic Dependency API<\/a> page, but the only mention of rank is<\/p>\n<blockquote class=\"q\"><p>When you call this API, you must pass in the dependency ID that was returned when you created the install-time reference, and the desired rank to use for the MSIX package in the process&#8217;s package graph.<\/p><\/blockquote>\n<p>So it tells me that I have to pass a rank, but it doesn&#8217;t tell me what the rank <i>means<\/i>.<\/p>\n<p>Okay, maybe I can get a clue from another API in the Windows App SDK: <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/windows-app-sdk\/api\/winrt\/microsoft.windows.widgets.providers.widgetinfo.rank?view=windows-app-sdk-2.0#:~:text=An%20integer%20specifying%20the%20relative%20rank,lower%20values.\"> The <code>Rank<\/code> property on the <code>WidgetInfo<\/code> class. Let&#8217;s see what that says. <\/a><\/p>\n<blockquote class=\"q\"><p>An integer specifying the relative rank of the widget. Smaller values are ranked higher than lower values.<\/p><\/blockquote>\n<p>Okay, so I learn that ranks are relative rather than absolute values. But that second sentence makes no sense: It says that smaller values are treated differently from lower values. Huh? What&#8217;s the difference between a &#8220;smaller value&#8221; and a &#8220;lower value&#8221;? And what does &#8220;higher&#8221; rank mean anyway?<\/p>\n<p>Unfortunately, the <a href=\"https:\/\/github.com\/microsoft\/WindowsAppSDK-Samples\/tree\/main\/Samples\/Widgets\"> Widget sample<\/a> doesn&#8217;t use the <code>Rank<\/code> property, so I still don&#8217;t know.<\/p>\n<p>This is just another example of the principle that &#8220;The person who understands the feature the best is often the person least qualified to explain it.&#8221; They know what the rank is. They&#8217;ve been working with ranks for months. To them, ranks are so obvious and intuitive that they don&#8217;t need an explanation.<\/p>\n<p><b>Bonus chatter<\/b>: I contacted a colleague who works on the package graph, who explained to me how it works and also lamented how the information provided to the documentation team somehow got garbled along the way. (And put fixing it onto the backlog.)<\/p>\n<p>The missing sentence is<\/p>\n<blockquote class=\"q\"><p>Packages are searched in ascending rank.<\/p><\/blockquote>\n<p>In other words, at least for the package graph, lower ranks have precedence over higher ranks.<\/p>\n<p>A process&#8217;s package graph is an ordered list of packages and is initially empty.<\/p>\n<p>If the process has declared dependencies, then all of those packages are added to the package graph with rank zero, in the order described by <a href=\"https:\/\/github.com\/microsoft\/WindowsAppSDK\/blob\/main\/specs\/dynamicdependencies\/DynamicDependencies.md#7-static-package-dependency-resolution-algorithm\"> static package dependency resolution algorithm<\/a>.<\/p>\n<p>Once that initial package graph is established, you can manually modify the graph by calling <code>Add\u00adPackage\u00adDependency<\/code> and <code>Remove\u00adPackage\u00adDependency<\/code>. When you add a package to the package graph, it is inserted into the graph after all the packages with lower rank and before all the packages with higher rank. By default, it also goes after all the packages with the same rank, but you can override this with <code>Add\u00adPackage\u00adDependency\u00adOptions_<wbr \/>Prepend\u00adIf\u00adRank\u00adCollision<\/code>, which will put it in front of all the packages with the same rank.<\/p>\n<p>In the package graph, the rank is a signed integer, so you can use a negative rank to go in front of the static package dependencies.<\/p>\n<p><b>Bonus bonus chatter<\/b>: In the world of filter drivers, the applicable term is <i>altitude<\/i>, and the meaning <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows-hardware\/drivers\/ifs\/load-order-groups-and-altitudes-for-minifilter-drivers#:~:text=The%20altitude%20is%20an%20infinite,higher%20numerical%20value.\"> is quite clearly spelled out<\/a>:<\/p>\n<blockquote class=\"q\"><p>The altitude is an infinite-precision string interpreted as a decimal number. A filter driver that has a low numerical altitude is loaded into the I\/O stack below a filter driver that has a higher numerical value.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>The problem with documentation written by people who know the feature too well.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-112830","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>The problem with documentation written by people who know the feature too well.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112830","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=112830"}],"version-history":[{"count":1,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112830\/revisions"}],"predecessor-version":[{"id":112833,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112830\/revisions\/112833"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=112830"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=112830"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=112830"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}