{"html_url": "https://github.com/simonw/datasette/issues/485#issuecomment-496038601", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/485", "id": 496038601, "node_id": "MDEyOklzc3VlQ29tbWVudDQ5NjAzODYwMQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-05-26T23:08:41Z", "updated_at": "2019-05-26T23:08:41Z", "author_association": "OWNER", "body": "The code currently assumes the primary key is called \"id\" or \"pk\" - improving it to detect the primary key using database introspection should work much better.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 447469253, "label": "Improvements to table label detection "}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/485#issuecomment-496039267", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/485", "id": 496039267, "node_id": "MDEyOklzc3VlQ29tbWVudDQ5NjAzOTI2Nw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-05-26T23:19:38Z", "updated_at": "2019-05-26T23:20:10Z", "author_association": "OWNER", "body": "Thinking about that union query: I imagine doing this with union could encourage multiple full table scans. Maybe this query would only do one? https://latest.datasette.io/fixtures?sql=select%0D%0A++count+%28distinct+name%29+as+count_distinct_column_1%2C%0D%0A++avg%28length%28name%29%29+as+avg_length_column_1%2C%0D%0A++count%28distinct+address%29+as+count_distinct_column_2%2C%0D%0A++avg%28length%28address%29%29+as+avg_length_column_2%0D%0Afrom+roadside_attractions\r\n\r\n```\r\nselect\r\n count (distinct name) as count_distinct_column_1,\r\n avg(length(name)) as avg_length_column_1,\r\n count(distinct address) as count_distinct_column_2,\r\n avg(length(address)) as avg_length_column_2\r\nfrom roadside_attractions\r\n```\r\n\r\n\"fixtures__select_count__distinct_name__as_count_distinct_column_1__avg_length_name___as_avg_length_column_1__count_distinct_address__as_count_distinct_column_2__avg_length_address___as_avg_length_column_2_from_roadside_attractions\"\r\n", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 447469253, "label": "Improvements to table label detection "}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/485#issuecomment-496039483", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/485", "id": 496039483, "node_id": "MDEyOklzc3VlQ29tbWVudDQ5NjAzOTQ4Mw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-05-26T23:22:53Z", "updated_at": "2019-05-26T23:22:53Z", "author_association": "OWNER", "body": "Comparing these two SQL queries (the one with union and the one without) using explain:\r\n\r\nWith union: https://latest.datasette.io/fixtures?sql=explain+select+%27name%27+as+column%2C+count+%28distinct+name%29+as+count_distinct%2C+avg%28length%28name%29%29+as+avg_length+from+roadside_attractions%0D%0A++union%0D%0Aselect+%27address%27+as+column%2C+count%28distinct+address%29+as+count_distinct%2C+avg%28length%28address%29%29+as+avg_length+from+roadside_attractions produces 52 rows\r\n\r\nWithout union: https://latest.datasette.io/fixtures?sql=explain+select%0D%0A++count+(distinct+name)+as+count_distinct_column_1%2C%0D%0A++avg(length(name))+as+avg_length_column_1%2C%0D%0A++count(distinct+address)+as+count_distinct_column_2%2C%0D%0A++avg(length(address))+as+avg_length_column_2%0D%0Afrom+roadside_attractions produces 32 rows\r\n\r\nSo I'm going to use the one without the union.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 447469253, "label": "Improvements to table label detection "}, "performed_via_github_app": null}