sql-server add tag
i-one
This question is based on my [Non-covering indexes and trivial optimization](https://topanswers.xyz/databases?q=1362) post. While writing it, I have made an observation regarding full optimization case that raised the question.

So, these were the rules applied during plan search

```none
---------------------------------------------------
Apply Rule: SelectToFilter - Select()->Filter()
---------------------------------------------------
Apply Rule: GetToScan - Get()->Scan()
---------------------------------------------------
Apply Rule: GetToIdxScan - Get -> IdxScan
```

The final physical plan is via `SelectToFilter` and `GetToIdxScan`.

Difference of snapshots of information returned by `sys.dm_exec_query_transformation_stats` before and after query compilation shows that all rules succeeded

| name | built_substitute | succeeded |
| ---- | ----------------:| ---------:|
| GetToIdxScan | 1 | 1 |
| GetToScan | 1 | 1 |
| SelectToFilter | 1 | 1 |

Following is what `GetToScan` rule generated

```none
---------------------------------------------------
Apply Rule: GetToScan - Get()->Scan()
    Args: Grp 3 0 LogOp_Get (Distance = 0)

Rule Result: group=3 1 <GetToScan>PhyOp_TableScan (Distance = 1)

Subst:
  PhyOp_TableScan TBL: #Data Bmk ( K) IsRow: COL: IsBaseRow1000 
```

The result of this rule (`group=3 1`) is not in the Final Memo Structure however

```none
--- Final Memo Structure ---
Root Group 4: Card=1 (Max=10000, Min=0)
   1 <SelectToFilter>PhyOp_Filter 3.2 2.0  Cost(RowGoal 0,ReW 0,ReB 0,Dist 0,Total 0)= 0.00782654 (Distance = 1)
   0 LogOp_Select 3 2 (Distance = 0)
Group 3: Card=1001 (Max=10000, Min=0)
   2 <GetToIdxScan>PhyOp_Range 1 ASC   Cost(RowGoal 0,ReW 0,ReB 0,Dist 0,Total 0)= 0.00734606 (Distance = 1)
   0 LogOp_Get (Distance = 0)
Group 2: 
   0 ScaOp_Comp  0.0 1.0  Cost(RowGoal 0,ReW 0,ReB 0,Dist 0,Total 0)= 3 (Distance = 0)
Group 1: 
   0 ScaOp_Const   Cost(RowGoal 0,ReW 0,ReB 0,Dist 0,Total 0)= 1 (Distance = 0)
Group 0: 
   0 ScaOp_Identifier   Cost(RowGoal 0,ReW 0,ReB 0,Dist 0,Total 0)= 1 (Distance = 0)
----------------------------
```

which means that this alternative was discarded.

Why was `PhyOp_TableScan` alternative discarded, and why does it not with `QUERYRULEOFF GetToIdxScan`? Why can alternatives be discarded in general, what is the mechanism?

This room is for discussion about this question.

Once logged in you can direct comments to any contributor here.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.