Bifalgorithm post

So this is what a database does when it has to process queries that need to sort the results. The database allocates a fixed size in memory buffer and it starts loading tuples or rows from disk into the buffer. If all the necessary tuples fit in memory, for example, if the table is only a few megabytes in size, then in that case, you can actually call dot sort on the buffer and that's it. You're done. You've sorted the entire table. But if you have to load more tuples than the buffer can fit, then the database dumps the memory buffer to a temporary file and it loads more tuples into the buffer again until it's full. Then it appends the results to the temporary file and it keeps doing that until it collects all the tuples into a temporary file with a format prepared for sorting.

So this is what a database does when it has to process queries that need to sort the results. The database allocates a fixed size in memory buffer and it start…

Ideas in this flowchart

  • Database Query Processing
  • Memory Buffer Allocation
  • Load Tuples into Buffer
  • All Tuples Fit in Memory
  • Sort Buffer
  • More Tuples than Buffer Capacity
  • Dump Buffer to Temporary File
  • Reload Buffer
  • Append to Temporary File
  • Prepare for Sorting
Feed/

So this is what a database does when it has to process queries that need to sort the results. The database allocates a fixed size in memory buffer and it starts loading tuples or rows from disk into the buffer. If all the necessary tuples fit in memory, for example, if the table is only a few megabytes in size, then in that case, you can actually call dot sort on the buffer and that's it. You're done. You've sorted the entire table. But if you have to load more tuples than the buffer can fit, then the database dumps the memory buffer to a temporary file and it loads more tuples into the buffer again until it's full. Then it appends the results to the temporary file and it keeps doing that until it collects all the tuples into a temporary file with a format prepared for sorting.

"what a database does when it has to process queries that need to sort the results."

👍
0
0 comments0 shares

Sign in to view and post comments.