How does this not make varchar2 ineffective?

Suppose I have a table with a column name varchar(20), and I save a row with the name = "abcdef".

INSERT INTO tab(id, name) values(12, 'abcdef');

How is the memory allocation allocated for namein this case?

I can think of two ways:

and)

20 bytes are allocated, but only 6 is used. In this case, it varchar2does not have any significant advantages compared with charthe point of view of memory allocation.

b)

Only 6 bytes are allocated. If so, and after that I added a few more lines,

INSERT INTO tab(id, name) values(13, 'yyyy');
INSERT INTO tab(id, name) values(14, 'zzzz');

and then I do UPDATE,

UPDATE tab SET name = 'abcdefghijkl' WHERE id = 12;

6 , ?. , 6 ( 6, - ).

, ? ( ).

+3
5

rdbms , :

, varchar. - , , .

, char . , .

, , , , , . , , .

+1

, , , , .

, , , , , - . , , - .

+1

. - , Microsoft SQL Server. , - ,

  • char, .
  • varchar, .
  • varchar (max), , 8 000 .

, . , .

, char NULL . Management Studio SQL Internals Viewer, , .

+1

, .

: MVCC . . - .

1-4 bytes of header + data (+ padding)

, . varchar .

+1

VARCHAR2 , , Oracle. Oracle PCTFREE. , .

, Oracle , , , ; ( ), .

This can lead to performance problems in cases where the table has a lot of access to the indexes, if a significant number of rows were wrapped, because it adds additional I / O to satisfy the queries.

+1
source

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


All Articles