I have nested set table (MySQL) with about 1.5 million records in it. The table structure is:
id | name | root_id | lft | rgt | level
I need to get strings, containing names of all parent records plus record name, let's call it 'full_name'. For example, it'll be
"United States, California, Los Angeles"
for "Los Angeles" record.
I may query all names for ONE record with:
SELECT parent.name
FROM location AS node,
location AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt
AND parent.root_id=node.root_id AND node.id=:id
ORDER BY parent.level
and to build full_name using implode()
But this request works for one record only, working too slowly for several calls. So now I want to add 'full_name' to Sphinx index (or probably to MySQL directly).
QUESTIONS:
Is it possible to construct such sql query that will select 'full_name' for each record to put it to Sphinx index? I think this would be ideal solution for such situation.
I also tried to update MySQL table adding 'full_name' field, but my update requests will take several days to finish the job. Is it good idea at all? Is it possible to make this update fast enough?
I'm thinking, maybe I should move to PostgreSQL and use hierarchical requests (I have no experience with this database so can't be sure) ?
Thank you