I have following rather simple query
select count(*) from tbl t1, tbl t2
For some reason it takes tens of seconds to execute this command. I wonder why it happens? It seems that it builds Cartesian product of that tables (table has about 270k rows), but amount of rows is obvious without building product.
Some clarifications would be helpful.
I would assume that the optimizer is not built to optimize for cartesian products (especially not for large tables as you mention). In your case it probably build the complete result set and counts it.
Rather than fight it, just count the table once
and build the product yourself.
(I assume that you have a more useful case in mind than the rather senseless self-join you posted :-), please add some more info on what you want to achieve.)