0

I have a PHP script which makes users able to search my databases. For these searches, I combine the data in a temporary table.

Let's say I have the following situation:

  • User 1 starts searching at 11:12:20 and the search takes 5 seconds to perform
  • User 2 starts searching at 11:12:24

This means that the temporary table, created for the search of user 1 is still active when user 2 starts to search. Let's say I have a 'solid / hardcoded' script which just states the name of the temporary table as TempTable.

Will the situation occur that the Temporary Table named TempTable can't be created because for User 2, because User 1 is still using it? Or is MySQL smart enough to assign a Temporary Table to a session?

So my question in short is: what is the scope of a temporary table?

TVA van Hesteren
  • 1,031
  • 3
  • 20
  • 47
  • Why do you need a temporary table in the first place? – Tim Biegeleisen Apr 02 '17 at 15:24
  • As stated in the question, my users are able to search my database**s** and therefore, I combine the data in a temporary table which makes it easier and faster to search through the relevant data since MySQL doesn't have to spool the data of each query-request to the browser / client – TVA van Hesteren Apr 02 '17 at 15:26
  • Surely creating a temp table.... Filling it... and then querying it takes longer and is more complicated than just querying the REAL tables – RiggsFolly Apr 02 '17 at 15:28
  • Also USER2 will never see USER1's temporary tables. They are related to a specific connection. – RiggsFolly Apr 02 '17 at 15:29
  • _This means that the temporary table, created for the search of user 1 is still active when user 2 starts to search_ **But not visible to or usable by User2** – RiggsFolly Apr 02 '17 at 15:31
  • @RiggsFolly, this is definitely not true since I benchmarked a lot. Besides that, how do you know what tables in 'merge' into a temp table? – TVA van Hesteren Apr 02 '17 at 15:32
  • @RiggsFolly, great so the scope of a Temporary Table is session specific. That's an answer I was looking for and related to the question, thanks – TVA van Hesteren Apr 02 '17 at 15:33

0 Answers0