We could remove the final "AND s.stainherit = p.inherited" in this part of the clause, too, right?
Right. With NOT p.inherited already restricting this clause to the non-inherited case, the stainherit filter is redundant since index stats never have stainherit = true (only leaf indexes accumulate stats, always with stainherit = false). I verified this holds across partitioned, inherited, and mixed scenarios. Removed in v3.