{"action":"created","issue":{"url":"https://api.github.com/repos/cockroachdb/cockroach/issues/32577","repository_url":"https://api.github.com/repos/cockroachdb/cockroach","labels_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/32577/labels{/name}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/32577/comments","events_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/32577/events","html_url":"https://github.com/cockroachdb/cockroach/issues/32577","id":383932705,"node_id":"MDU6SXNzdWUzODM5MzI3MDU=","number":32577,"title":"opt: top-k sort is not planned","user":{"login":"jordanlewis","id":43821,"node_id":"MDQ6VXNlcjQzODIx","avatar_url":"https://avatars1.githubusercontent.com/u/43821?v=4","gravatar_id":"","url":"https://api.github.com/users/jordanlewis","html_url":"https://github.com/jordanlewis","followers_url":"https://api.github.com/users/jordanlewis/followers","following_url":"https://api.github.com/users/jordanlewis/following{/other_user}","gists_url":"https://api.github.com/users/jordanlewis/gists{/gist_id}","starred_url":"https://api.github.com/users/jordanlewis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jordanlewis/subscriptions","organizations_url":"https://api.github.com/users/jordanlewis/orgs","repos_url":"https://api.github.com/users/jordanlewis/repos","events_url":"https://api.github.com/users/jordanlewis/events{/privacy}","received_events_url":"https://api.github.com/users/jordanlewis/received_events","type":"User","site_admin":false},"labels":[{"id":843052634,"node_id":"MDU6TGFiZWw4NDMwNTI2MzQ=","url":"https://api.github.com/repos/cockroachdb/cockroach/labels/A-sql-planning","name":"A-sql-planning","color":"22aa88","default":false},{"id":78928345,"node_id":"MDU6TGFiZWw3ODkyODM0NQ==","url":"https://api.github.com/repos/cockroachdb/cockroach/labels/C-bug","name":"C-bug","color":"c5def5","default":false}],"state":"open","locked":false,"assignee":{"login":"RaduBerinde","id":16544120,"node_id":"MDQ6VXNlcjE2NTQ0MTIw","avatar_url":"https://avatars1.githubusercontent.com/u/16544120?v=4","gravatar_id":"","url":"https://api.github.com/users/RaduBerinde","html_url":"https://github.com/RaduBerinde","followers_url":"https://api.github.com/users/RaduBerinde/followers","following_url":"https://api.github.com/users/RaduBerinde/following{/other_user}","gists_url":"https://api.github.com/users/RaduBerinde/gists{/gist_id}","starred_url":"https://api.github.com/users/RaduBerinde/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RaduBerinde/subscriptions","organizations_url":"https://api.github.com/users/RaduBerinde/orgs","repos_url":"https://api.github.com/users/RaduBerinde/repos","events_url":"https://api.github.com/users/RaduBerinde/events{/privacy}","received_events_url":"https://api.github.com/users/RaduBerinde/received_events","type":"User","site_admin":false},"assignees":[{"login":"RaduBerinde","id":16544120,"node_id":"MDQ6VXNlcjE2NTQ0MTIw","avatar_url":"https://avatars1.githubusercontent.com/u/16544120?v=4","gravatar_id":"","url":"https://api.github.com/users/RaduBerinde","html_url":"https://github.com/RaduBerinde","followers_url":"https://api.github.com/users/RaduBerinde/followers","following_url":"https://api.github.com/users/RaduBerinde/following{/other_user}","gists_url":"https://api.github.com/users/RaduBerinde/gists{/gist_id}","starred_url":"https://api.github.com/users/RaduBerinde/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RaduBerinde/subscriptions","organizations_url":"https://api.github.com/users/RaduBerinde/orgs","repos_url":"https://api.github.com/users/RaduBerinde/repos","events_url":"https://api.github.com/users/RaduBerinde/events{/privacy}","received_events_url":"https://api.github.com/users/RaduBerinde/received_events","type":"User","site_admin":false},{"login":"andy-kimball","id":32096062,"node_id":"MDQ6VXNlcjMyMDk2MDYy","avatar_url":"https://avatars0.githubusercontent.com/u/32096062?v=4","gravatar_id":"","url":"https://api.github.com/users/andy-kimball","html_url":"https://github.com/andy-kimball","followers_url":"https://api.github.com/users/andy-kimball/followers","following_url":"https://api.github.com/users/andy-kimball/following{/other_user}","gists_url":"https://api.github.com/users/andy-kimball/gists{/gist_id}","starred_url":"https://api.github.com/users/andy-kimball/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andy-kimball/subscriptions","organizations_url":"https://api.github.com/users/andy-kimball/orgs","repos_url":"https://api.github.com/users/andy-kimball/repos","events_url":"https://api.github.com/users/andy-kimball/events{/privacy}","received_events_url":"https://api.github.com/users/andy-kimball/received_events","type":"User","site_admin":false}],"milestone":null,"comments":2,"created_at":"2018-11-23T21:57:44Z","updated_at":"2018-11-26T19:08:29Z","closed_at":null,"author_association":"MEMBER","body":"Given the simple table:\r\n\r\n```\r\nroot@127.0.0.1:65097/defaultdb> create table a (a int);\r\nCREATE TABLE\r\n```\r\n\r\nEXPECTED (with `optimizer=off`):\r\n\r\n```\r\nroot@127.0.0.1:65097/defaultdb> explain select * from a order by a limit 1;\r\n         tree         |  field   | description\r\n+---------------------+----------+-------------+\r\n  limit               |          |\r\n   │                  | count    | 1\r\n   └── sort           |          |\r\n        │             | order    | +a\r\n        │             | strategy | top 1\r\n        └── render    |          |\r\n             └── scan |          |\r\n                      | table    | a@primary\r\n                      | spans    | ALL\r\n(9 rows)\r\n```\r\n\r\nACTUAL: (with `optimizer=on`):\r\n\r\n```\r\nroot@127.0.0.1:65097/defaultdb> explain select * from a order by a limit 1;\r\n       tree      | field | description\r\n+----------------+-------+-------------+\r\n  limit          |       |\r\n   │             | count | 1\r\n   └── sort      |       |\r\n        │        | order | +a\r\n        └── scan |       |\r\n                 | table | a@primary\r\n                 | spans | ALL\r\n```\r\n\r\nThe top-k strategy is more efficient than the full-sort strategy. We should be choosing it when possible (when there's a limit).\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/cockroachdb/cockroach/issues/comments/441759141","html_url":"https://github.com/cockroachdb/cockroach/issues/32577#issuecomment-441759141","issue_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/32577","id":441759141,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MTc1OTE0MQ==","user":{"login":"RaduBerinde","id":16544120,"node_id":"MDQ6VXNlcjE2NTQ0MTIw","avatar_url":"https://avatars1.githubusercontent.com/u/16544120?v=4","gravatar_id":"","url":"https://api.github.com/users/RaduBerinde","html_url":"https://github.com/RaduBerinde","followers_url":"https://api.github.com/users/RaduBerinde/followers","following_url":"https://api.github.com/users/RaduBerinde/following{/other_user}","gists_url":"https://api.github.com/users/RaduBerinde/gists{/gist_id}","starred_url":"https://api.github.com/users/RaduBerinde/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RaduBerinde/subscriptions","organizations_url":"https://api.github.com/users/RaduBerinde/orgs","repos_url":"https://api.github.com/users/RaduBerinde/repos","events_url":"https://api.github.com/users/RaduBerinde/events{/privacy}","received_events_url":"https://api.github.com/users/RaduBerinde/received_events","type":"User","site_admin":false},"created_at":"2018-11-26T19:08:29Z","updated_at":"2018-11-26T19:08:29Z","author_association":"MEMBER","body":"@jordanlewis the distsql planner doesn't look at `sortStrategy`.. The top K strategy is used automatically if the sort processor has a Limit.\r\n\r\nThe optimizer doesn't have any knowledge of this optimization currently. It should, at least from a costing perspective. But in practice, the distsql plan should be as desired in most cases."}}
{"actor":{"display_login":"RaduBerinde"}}