I have a MySQL MyISAM table that stores a URL in a url
field. The URL is always just the scheme, subdomain, and host ( eg. http://www.site.com or https://site2.edu ).
I need to store the Domain, the Subdomain, and the Scheme in their own fields so I can index them and search them. It's too slow for my system to do a LIKE query on millions of rows.
- Domain: site.com, site2.com
- Subdomain: www, ''
- Scheme: http, https
How do I create a MySQL Trigger to do this? It will need to extract the Domain, Subdomain, and Scheme from the URL field every time it is updated and then store them in their respective fields ( eg. domain
, subdomain
, scheme
) These fields will only be written to by the MySQL trigger.
I realize parsing URLs is often non-trivial, so I'm mostly concerned with setting up a trigger to do something like this. I can make adjustments and tradeoffs on the quality of URL parsing in my application.