From 21f8ca50d99ee74f8fd866582f8f2688c2fb50e6 Mon Sep 17 00:00:00 2001 From: Johnathan Douglas Date: Mon, 10 Jul 2023 09:53:47 -0300 Subject: [PATCH] insert read --- README.md | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a1f08e6..6bfc5fe 100755 --- a/README.md +++ b/README.md @@ -25,7 +25,68 @@ run migrate; php artisan migrate:fresh --seed ``` -# Result +# Insert + +Inserir um registro por vez. + +`Insert1` + +```sql +insert into transactions (id, value, date) +values (1, 10, '2023-04-01'); + +insert into transactions (id, value, date) +values (2, 20, '2023-04-02'); + +insert into transactions (id, value, date) +values (3, 30, '2023-04-03'); +``` + +`Insert2` + +```sql +insert into transactions (id, value, date) +values (1, 10, '2023-04-01'), + (2, 20, '2023-04-02'), + (3, 30, '2023-04-03'), ....; +``` + +> Nesse modelo, a quantidade de parametros acaba estourando, limitando dessa forma a quantidade máxima que pode ser +> inserido: +> +> SQLSTATE[HY000]: General error: 7 number of parameters must be between 0 and 65535 + + +`Insert3` + +```sql +insert into transactions (id, value, date) +values (1, 10, '2023-04-01'), + (2, 20, '2023-04-02'), + (3, 30, '2023-04-03'), ....; --limit 1.000 + +insert into transactions (id, value, date) +values (1001, 50, '2023-04-01'), + (1002, 60, '2023-04-02'), + (1003, 70, '2023-04-03'), ....; --limit 1.000 +``` + +| quantity | method | time seconds | performance | +|----------:|---------|-----------------:|------------:| +| 1.000 | Insert1 | 1,44s | - | +| 1.000 | Insert2 | 0,09s | - | +| 1.000 | Insert3 | 0,09s | - | +| 10.000 | Insert1 | 14,25s | - | +| 10.000 | Insert2 | 0,88s | - | +| 10.000 | Insert3 | 0,83s | - | +| 100.000 | Insert1 | (2m 38s) 158,41s | - | +| 100.000 | Insert2 | `error` | - | +| 100.000 | Insert3 | 8,25s | - | +| 1.000.000 | Insert1 | - | - | +| 1.000.000 | Insert2 | `error` | - | +| 1.000.000 | Insert3 | (1m 35s) 95s | - | + +# Update ### Grupo 1: