Use an index when sorting
When working with a database it is a very common task to retrieve a sorted list of entities. What you might not realize is that this can be a very expensive operation.
I am a programmer from Donegal, Ireland. I enjoy making things on the web and writing about my findings. My hope is that you will find something here that piques your interest and that you will drop me an email to say hi.
I've been programming for 14 years and I am grateful for the life it has afforded me. I do not take it forgranted.
When working with a database it is a very common task to retrieve a sorted list of entities. What you might not realize is that this can be a very expensive operation.
I've been doing a lot of web scraping for various AI tools. This includes model training, and search functionality. One thing I find myself doing is generating lots of prototypes.
Each prototype requires me to write a new db schema and one thing they share in common is the need for a http_status_codes
table to record the final status response of a web page. You could store the value as an int, or string, or even as json to
make it queryable. But I feel taking the time to create and populate a table of the status codes is much more advantageous
for querying and indexing. So to help future Brian I have pasted the code used to generate this table below.
When working with an instance of a MariaDB database I noticed that the npm package used to connect did not support Typescript generics. This was something I felt I could fix, so I sent in a PR.