My main storage is MySQL, but I have to use remote MSSQL Server, where book titles and IDs are stored. I have read-only access to that remote MSSQL Server. All other data (book author, year, description and so on) is stored in my local MySQL database. I can not store titles in my local MySQL (it is agreement conditions). My PHP-framework allows to add descriptions and many other data for these books – all data stored in MySQL.
Overall I am OK developing this framework, but I have one weak point. I need professional advice on how to organize search in that case. Since I use 2 different dbs I cant use simple joins or what ever. Of course, I can do two-step search: 1) get titles, 2) get other stuff, and then form results in PHP. But I am afraid it can be very slow. Is there a way to somehow select titles from MSSQL in temporary table of MySQL? Or may be I miss some good technology for such databases cooperation?
Any thoughts are highly appreciated!
MySQL doesn’t know anything about MSSQL, so you cannot join across the two different kinds of database servers. However, your structure really isn’t too bad for what you describe. It seems to me that You have three possible search scenarios 1) search titles only 2) search titles and other info, 3) search other info only. You problem is in case 2, case 1 and 3 are both easy.
The way I’d approach it is a two step process, as you mentioned, kind of like this:
1) Get search query
2) Get MSSQL results for any title that could possibly match
3) Either a) write title results into a temporary table or b) store in a memory structure (depends on what you’re using for your search result scoring – if using MySQL fulltext search, need to write to temp table)
4a) if titles are in a temp table, perform search on joined tables
4b) if title are in memory, search other book info and join data in memory as necessary.
You’re going to have some performance issues no matter what due to the limitation of not storing titles locally, but minimizing the number of queries will help.
P.S. What exactly does your agreement say? Can you store the book titles in memory? Or do you always have to perform a query against the remote server? If you can store them in memory, maybe you could query the MSSQL database and put the titles in a MySQL memory table (http://dev.mysql.com/doc/refman/5.0/en/memory-storage-engine.html), which disappears from memory when the server shuts down.