It might be good to track how many items have wikidata IDs in the osm database. This will tell us if we need to invest any efforts into this.
SELECT COUNT(DISTINCT tags->'wikidata') FROM planet_osm_polygon WHERE tags ? 'wikidata'; -- Result: 39757
This post suggests that this query would be faster, but I am not sure - it seems once the query is cached, it is almost instantenious in both cases:
SELECT COUNT(*) FROM (SELECT DISTINCT tags->'wikidata' as wikidata FROM planet_osm_polygon WHERE tags ? 'wikidata') AS tmp;