Mysql – What’s the difference between a thread vs. a process

MySQL

Specifically regarding MySQL, what is the difference between a thread and a process? The documentation seems to refer to them interchangeably at times, and it even throws in the term "session" too.

At the most basic level, the command to show threads includes the term PROCESSLIST, as if a list of processes is a list of threads. (https://dev.mysql.com/doc/refman/5.6/en/show-processlist.html — The first sentence says this list "shows which threads are running.") But then, in the performance_schema.threads table, each thread there has its own unique thread_id that is not the ID returned from SHOW [FULL] PROCESSLIST. Instead, PROCESSLIST_ID is a foreign key to the PROCESSLIST (https://dev.mysql.com/doc/refman/5.6/en/threads-table.html). This leads me to believe that threads and processes are not the same thing.

Best Answer

MySQL has been implemented on a lot of Operating Systems -- From Atari to Windows to Solaris to Linux. Different OSs work differently when it comes to "processes" versus "threads". MySQL picked whichever was better in each case. Then it got sloppy in saying "THREADS_runnng" and "show PROCESSlist".

So, in MySQL context, "threads" and "processes" are synonymous.

In Operating System context, they are different enough to necessitate multiple courses in Computer Science.

In MySQL, one connection uses one thread (or process). There is also a main thread (process) for coordinating between the connections. Also, InnoDB has some extra threads (which may actually be threads and not processes?) to deal with background I/O tasks.