📜 ⬆️ ⬇️

PHP Database Engine

Hello, dear readers. My DBMS is not a port of any of the existing DBMS on PHP (unlike C # -SQLITE , for example), but is a unique development. The main difference from existing engines, like TxtSQL , is index support. If only PRIMARY INDEX is used, the insertion speed on my laptop reaches 5000 / sec. For PHP, it seems to me, this is quite good.

What for?


The main goal for me was initially a purely theoretical interest; there was always a desire to make a replacement for the MySQL functions in PHP, to make most of the scripts that are tied to MySQL work without the support of it.

Before writing the SQL parser, you need to create a platform on which this same DBMS should hold. Initially, I used phpTable for these purposes, but since it does not support indexes, processing large amounts of information was impossible. I also did not find any other DBMS with index support, so I had to create a kernel for the database myself. I have been developing it for quite a long time, and have gone through several evolutionary steps, for example, adding support for B-trees and organizing indices based on them.

I post it here in the form in which it is now, because I am looking for people who could help me with the development. For example, in my DBMS there is no SQL support, and I would like to add such support, while I myself would like to be engaged in the further development of the core database.
')

What is it like


At this stage, the core of the database is at an early stage of development, and from the version that I present here, some pieces of the debugging code have not even been removed. Of course, you can remove them and use the DBMS right now, but I would like to focus your attention not on this. If you can not wait to see the core "in battle", I have a demo:

Database forum forum.dklab.ru, imported into a self-made forum

Initially, the forum used MySQL, but it was modified to work with the core of my DBMS (this process took not very long, just a few hours). The forum.dklab.ru database contains about 150,000 messages, the database with messages takes about 60 MB (I can send the source to anyone).

Current DB capabilities


At the moment, the database supports AUTO_INCREMENT fields, which are also PRIMARY INDEX, as well as analogs of INDEX and UNIQUE indices in MySQL. There is support for multiple indexed fields. There is currently no support for composite indexes, and it is not planned yet. Also, only numeric fields (INT) are available for indexing.

The syntax of the method, which is used to select strings, currently involves selecting only one condition of the form “ field_name operator value ”, where the operator can be one of the following: "> <= IN". Indexes are used for queries of the form " field_name = value", and only for them. For PRIMARY INDEX, there is also a sample optimization using the IN operator (this is a complete analogue of the same in MySQL).

Despite the fact that these opportunities may seem quite small, this is quite enough to make, for example, a forum or CMS based on my core.

Technical Details


PRIMARY INDEX ( AUTO_INCREMENT ) , , : id*4 (4 = sizeof(int)) . .

UNIQUE -. , - ( ~log(- ) / log(70) ), — .

INDEX -, . , INDEX .

32-, 2 , . , «» — unix

cat *.idx *.btr *.pri > /dev/null

, . , .



, .

$db = new YNDb('my_data');

— . , — , .

$db->create('test_table', array('id' => 'INT', 'name' => 'TINYTEXT'), array('AUTO_INCREMENT' => 'id') );

:

for($i = 0; $i < 100; $i++)
{
$db->insert('test_table', array('name' => 'value'.$i));
}


, , limit', .. :

$results = $db->select('test_table', array('cond' => 'id > 30', 'limit' => '30,50', 'order' => array('name', SORT_ASC) ) );

* This source code was highlighted with Source Code Highlighter
.


?


Google Code:

code.google.com/p/yndb

, , , «YNDbAdmin» — 300 , .

:)!

Source: https://habr.com/ru/post/70140/


All Articles