security_uid_field_list = [x + ("_" if x != "" else "") + "security_uid" for x in portal.portal_catalog.getSQLCatalog().getSQLCatalogSecurityUidGroupsColumnsDict().keys()]\n
referenced_uid_set = set()\n
all_uid_set = set()\n
for security_uid_field in security_uid_field_list:\n
referenced_uid_set.union({getattr(row, security_uid_field) for row in req("select distinct %s from catalog where %s is not NULL" % (security_uid_field, security_uid_field))})\n
\n
print(">> useless uids in roles_and_users table <<\\n")\n
if len(referenced_uid_set) > 0:\n
for row in req("select * from roles_and_users where uid not in %s" + tuple(referenced_uid_set)):\n