Question: Why when I am using javascript the basic HTML inputs validation not performed?  

Say the min max attributes.

Here the HTML:

```
<form action="#" method="get">Quantity (between 1 and 5):
    <input type="number" name="quantity" min="1" max="5">
    <br />
    <input type="submit" value="with HTML">
</form>
<button id="sender">with JS</button>

```

JS:

```
$("#sender").click(function (event) {
    $("form").submit();
});

```

And live example: <http://jsfiddle.net/txP4R/2/>

Answer: 
MySQL is probably already doing what you describe, as much as it can.

In the case of InnoDB (which should be your default storage engine with MySQL), inserts and updates and deletes change primary key or unique key indexes immediately. But they never rebuild the *whole* index, they add new values into (or take values out of) these indexes.

For non-unique indexes, InnoDB performs [change buffering](https://dev.mysql.com/doc/refman/en/innodb-change-buffer.html). That is, it queues the changes, which will be merged into the index later in the background. It will even consolidate changes so that the physical updates to the index are done more efficiently.

You don't have to do anything to enable this feature, because it's enabled by default. MySQL 5.1 does change buffering only for `INSERT`. MySQL 5.5 and later additionally does change buffering for `UPDATE` and `DELETE`.

You can *disable* this feature if you want (for instance if you use SSD, avoiding random I/O is not so important, and you might want to ensure that queued changes don't accumulate). Normally, you should keep the feature enabled.
> 
> When MySQL updates the index due to an insert, does it rebuild the
>  entire index?
> 
> 
> 

No, MySQL doesn't "rebuild" the index on each insert.

MySQL's default page size is 16K. It allocates these pages in 1MB increments (called extents).

When a table is first created (indexes are rebuilt), the pages are filled up 15/16th full, leaving room for some random inserts. If your index entries are 500 bytes each each (primary key size + row data for a clustered index), that leaves room for 2 new rows to be inserted before having to split the page.

When MySQL needs to insert a row on a full page, the page must be split. MySQL will add a new page, and move half of the page data to the new page.

Within a page, records may not actually be in physical order. They'll be in the order they were inserted. They're linked in order via a form of linked list. So, even a random insert doesn't cause data to be physically reordered. Outside the need to split a page, the data isn't moved around.

After may random inserts, your pages will be from 1/2 full to full.

All of this work does affect your insert performance, as the index must be updated with each insert. In addition, an index with many half full pages will negatively affect read performance.

Now, if you're inserting rows in index order, then MySQL simply keeps adding to the end of the pages, filling them up 15/16 full, and adding an extent at a time of pages. Much less performance penalty since there is no splitting of pages, hence no moving of data is involved, not to mention the read performance benefit of nearly full pages.

So, while there is some maintenance involved in updating an index for inserts, MySQL isn't "rebuilding" the index on each insert. Also, see Bill Karwin's [note about change buffering](https://stackoverflow.com/a/23435759/168493), which may affect you.