If you are using the new DB then you also have access to a new template function that returns a list of virtual libraries that a book is in. The function is virtual_libraries(). A (template program mode) template that uses it is
Code:
{0:'virtual_libraries()'}
The performance of this function should be adequate if you don't have "lots" of virtual libraries. One question: is this true? Second question: how many is "lots"? I think that "lots" is more than 10 or so, and is certainly more than 50.
Note that if you sort on this column then calibre must compute the values for every book in the db, which might be slow for large libraries, although with the composite column evaluation optimizations in the new DB this effect might be not as noticeable. If you don't sort on it then the values are computed when displayed.
This function is not available in the old DB.