Hi all,

The execution plan for this query [1] indicates that it will be entirely based on existing indexes. Yet in practice, the query takes a long time to run. Why is that?

Also, interestingly, the execution plan for this modified version [2] is identical, but it runs almost instantaneously.

Lastly, I expect that last query to return no results (because the NOT EXISTS condition should not be met) but it does return a row. Why is that?

Thanks!

Huji

[1] https://tools.wmflabs.org/sql-optimizer?use=enwiki_p&sql=use+fawiki_p%3B%0D%0Aselect%0D%0A++p1.page_title%2C%0D%0A++tl_title%2C%0D%0A++p2.page_title%0D%0Afrom+templatelinks%0D%0Ajoin+page+p1%0D%0A++on+p1.page_id+%3D+tl_from%0D%0A++and+p1.page_title+like+%27%DA%AF%D8%B2%D8%A7%D8%B1%D8%B4_%D8%AF%DB%8C%D8%AA%D8%A7%D8%A8%DB%8C%D8%B3%2F%25%27%0D%0A++and+tl_title+like+%27%25%2F%D8%A8%D8%A7%D9%84%D8%A7%27%0D%0A++and+tl_namespace+%3D+4%0D%0A++and+p1.page_namespace+%3D+4%0D%0Aleft+join+page+p2%0D%0A++on+p2.page_title+%3D+tl_title%0D%0A++and+p2.page_namespace+%3D+4%0D%0Awhere%0D%0A++p2.page_title+is+null%0D%0A++and+tl_from+%3D+4859256

[2] https://tools.wmflabs.org/sql-optimizer?use=fawiki_p&sql=select%0D%0A++p1.page_title%2C%0D%0A++tl_title%0D%0Afrom+templatelinks%0D%0Ajoin+page+p1%0D%0A++on+p1.page_id+%3D+tl_from%0D%0A++and+p1.page_title+like+%27%DA%AF%D8%B2%D8%A7%D8%B1%D8%B4_%D8%AF%DB%8C%D8%AA%D8%A7%D8%A8%DB%8C%D8%B3%2F%25%27%0D%0A++and+tl_title+like+%27%25%2F%D8%A8%D8%A7%D9%84%D8%A7%27%0D%0A++and+tl_namespace+%3D+4%0D%0A++and+p1.page_namespace+%3D+4%0D%0Aleft+join+page+p2%0D%0A++on+p2.page_title+%3D+tl_title%0D%0A++and+p2.page_namespace+%3D+4%0D%0Awhere%0D%0A++p2.page_title+is+null%0D%0A++and+tl_from+%3D+4859256