Tokenizer: Is responsible for splitting the inputed SQL statements into separate tokens, by doing a lexical analysis on the input.It parses the statements (and commands), optimizes them, and as I mentioned before, generates equivalent SQLite internal bytecode so that the backend can execute. The frontend compiles each SQL statement and the backend executes the compiled statement.Īs I mentioned the frontend pre-processes SQL statements as well as SQLite commands that are then sent as inputs. The architecture consists of seven major components, partitioned into two parts. SQLite is designed with a very modular architecture. The statement that has been compiled into binary form ( bytecode) is ready to be evaluated and is passed on to the virtual machine, which in turn runs the program until it either completes, or forms a row of results to be returned, or hits a fatal error, or is interrupted.Ī query on SQLite goes through a specific chain of components in order to interact with actual data. This bytecode is basically a sqlite3_stmt object that implements a single SQL statement. The SQLite interfaces act as a compiler by converting SQL text into bytecode. SQLite works by compiling SQL text into bytecode, then running that bytecode using a virtual machine. Plus I’ve got a copy of SQLite Database System: Design and Implementation, that was a great help understanding some concepts. Thankfully the documentation on their website is quite good, Architecture of SQLite. If I really understand how it works and I have a step by step and a clear goal than the coding part will be piece of cake. Anyway, I am saying this because I do plan to take my time on each part and really dig in to the works of how SQLite was designed so I can try to replicate. But a lot of times if we rush the process we probably will have to go back and redo the entire thing. I know, it's fun to build things our of nothing and see them working. If you spend enough time on planning, coding is easy.Īs software developers I think it is in our nature to want to get our hands dirty and see things working fast. I am not in a hurry, are you?Ī former colleague of mine used to say something that really stuck to me and that was that: The goal is to have a simple relational database contained in a single file and modeled after SQLite.Īnd for that my plan is to both, one take my time and second take one step at a time, with each post I plan to add one or two features and let's see how long this will take. My intention here, at least at first, is not to deliver a full on replacement with all the features available. Also, I want to develop a small database, contained in a single file, with the main goal of improving my understanding of it, and for that we don't need so many features as big distributed database.Īlso I think it is important to say that even SQLite it self has a lot of features! You can see that even by typing sqlite3 -help. Why SQLite? Well, because I just don't have the time write something like MySQL or PostgreSQL, and possibly not the expertise either. To get there I want to write a database from scratch, in Rust and I will model it after the existing and popular SQLite. What extra features can we add to our DB, if any?.What format is a prepared statement saved in?.When and how does a full table scan happen? Does it happen every time we issue a query? Do the indexes help? How?. How are indexes formatted? And how do they work?.How does rolling back a transaction work?.Why we only have one primary key per table? Do you know?.When does it move from memory to disk? How would that work exactly?.What format is data saved in? In our case, in memory and on disk.Like I said in the previous post, here are some of the questions I want to be able to answer: To be honest, a lot of what goes on behind the curtains with databases is still a black box to me, even after almost 2 decades working as a software developer. I think there isn't a developer out there that hasn't used at least one of the relational databases available out there, but do they really know how they work. Part 2 - SQL Statement and Meta Commands Parser + Error Handling → Writing a SQLite clone from scratch in Rust What would SQLite look like if written in Rust? - Part 1
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |