Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes for using various types in keys #1171

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Conversation

zachmu
Copy link
Member

@zachmu zachmu commented Feb 5, 2025

This PR allows various types to be used in keys that were not possible before. This comes down to two things:

  1. Swap out the validateCreateTable analyzer rule
  2. Change the determination for the max width of a type to be more accurate, which influences whether we choose standard extended encoding or extended address encoding
  3. Alter the way we determine the encoding type for extended columns in keys to more closely match the non-key case (Bug fix for encoding extended types in keys dolt#8817)

This PR also has a couple small regressions in tests. I'm punting on these because we're about to completely overhaul how we store these types (to implement toast semantics).

@zachmu zachmu requested a review from Hydrocharged February 5, 2025 02:11
Copy link
Contributor

github-actions bot commented Feb 5, 2025

Main PR
covering_index_scan_postgres 361.74/s 371.35/s +2.6%
index_join_postgres 154.32/s 155.29/s +0.6%
index_join_scan_postgres 184.66/s 185.59/s +0.5%
index_scan_postgres 12.51/s 12.68/s +1.3%
oltp_point_select 2789.45/s 2855.56/s +2.3%
oltp_read_only 1890.22/s 1925.52/s +1.8%
select_random_points 114.09/s 112.19/s -1.7%
select_random_ranges 127.79/s 128.48/s +0.5%
table_scan_postgres 11.89/s 11.18/s -6.0%
types_table_scan_postgres 5.61/s 5.62/s +0.1%

Copy link
Contributor

github-actions bot commented Feb 5, 2025

Main PR
Total 42090 42090
Successful 15537 15574
Failures 26553 26516
Partial Successes1 5226 5224
Main PR
Successful 36.9138% 37.0017%
Failures 63.0862% 62.9983%

${\color{lightgreen}Progressions (39)}$

conversion

QUERY: CREATE TABLE utf8_verification_inputs (inbytes bytea, description text PRIMARY KEY);
QUERY: insert into utf8_verification_inputs  values
  ('\x66006f',	'NUL byte'),
  ('\xaf',		'bare continuation'),
  ('\xc5',		'missing second byte in 2-byte char'),
  ('\xc080',	'smallest 2-byte overlong'),
  ('\xc1bf',	'largest 2-byte overlong'),
  ('\xc280',	'next 2-byte after overlongs'),
  ('\xdfbf',	'largest 2-byte'),
  ('\xe9af',	'missing third byte in 3-byte char'),
  ('\xe08080',	'smallest 3-byte overlong'),
  ('\xe09fbf',	'largest 3-byte overlong'),
  ('\xe0a080',	'next 3-byte after overlong'),
  ('\xed9fbf',	'last before surrogates'),
  ('\xeda080',	'smallest surrogate'),
  ('\xedbfbf',	'largest surrogate'),
  ('\xee8080',	'next after surrogates'),
  ('\xefbfbf',	'largest 3-byte'),
  ('\xf1afbf',	'missing fourth byte in 4-byte char'),
  ('\xf0808080',	'smallest 4-byte overlong'),
  ('\xf08fbfbf',	'largest 4-byte overlong'),
  ('\xf0908080',	'next 4-byte after overlong'),
  ('\xf48fbfbf',	'largest 4-byte'),
  ('\xf4908080',	'smallest too large'),
  ('\xfa9a9a8a8a',	'5-byte');

create_table_like

QUERY: CREATE TABLE ctlt1 (a text CHECK (length(a) > 2) PRIMARY KEY, b text);
QUERY: CREATE INDEX ctlt1_b_key ON ctlt1 (b);

enum

QUERY: CREATE TABLE enumtest_parent (id rainbow PRIMARY KEY);
QUERY: INSERT INTO enumtest_parent VALUES ('red');
QUERY: DROP TABLE enumtest_parent;

join

QUERY: create temp table a (
     code char not null,
     constraint a_pk primary key (code)
);
QUERY: create temp table b (
     a char not null,
     num integer not null,
     constraint b_pk primary key (a, num)
);
QUERY: create temp table c (
     name char not null,
     a char,
     constraint c_pk primary key (name)
);
QUERY: insert into c (name, a) values ('A', 'p');
QUERY: insert into c (name, a) values ('B', 'q');
QUERY: insert into c (name, a) values ('C', null);

jsonb

QUERY: SELECT count(*) FROM testjsonb WHERE j > '{"p":1}';

rowsecurity

QUERY: CREATE TABLE uaccount (
    pguser      name primary key,
    seclv       int
);
QUERY: INSERT INTO uaccount VALUES
    ('regress_rls_alice', 99),
    ('regress_rls_bob', 1),
    ('regress_rls_carol', 2),
    ('regress_rls_dave', 3);

rules

QUERY: CREATE TABLE hats (
	hat_name    char(10) primary key,
	hat_color   char(10)      -- hat color
);
QUERY: drop table hats;

strings

QUERY: CREATE TABLE texttest (a text PRIMARY KEY, b int);
QUERY: SELECT * FROM texttest WHERE a LIKE '%1%';
QUERY: CREATE TABLE byteatest (a bytea PRIMARY KEY, b int);
QUERY: SELECT * FROM byteatest WHERE a LIKE '%1%';
QUERY: DROP TABLE texttest, byteatest;

triggers

QUERY: create table convslot_test_parent (col1 text primary key);
QUERY: alter table convslot_test_child add column col2 text not null default 'tutu';
QUERY: insert into convslot_test_parent(col1) values ('1');
QUERY: insert into convslot_test_child(col1) values ('1');
QUERY: insert into convslot_test_parent(col1) values ('3');
QUERY: insert into convslot_test_child(col1) values ('3');
QUERY: update convslot_test_parent set col1 = col1 || '1';
QUERY: update convslot_test_parent set col1 = col1 || '1';
QUERY: delete from convslot_test_parent;
QUERY: drop table convslot_test_child, convslot_test_parent;

union

QUERY: CREATE TEMP TABLE t2 (ab text primary key);
QUERY: INSERT INTO t2 VALUES ('ab'), ('xy');

uuid

QUERY: INSERT INTO guid1(guid_field) VALUES('44444444-4444-4444-4444-444444444444');
QUERY: SELECT COUNT(*) FROM guid1 g1 LEFT JOIN guid2 g2 ON g1.guid_field = g2.guid_field WHERE g2.guid_field IS NULL;
QUERY: INSERT INTO guid1 (guid_field) VALUES (gen_random_uuid());
QUERY: INSERT INTO guid1 (guid_field) VALUES (gen_random_uuid());

Footnotes

  1. These are tests that we're marking as Successful, however they do not match the expected output in some way. This is due to small differences, such as different wording on the error messages, or the column names being incorrect while the data itself is correct.

Copy link
Collaborator

@Hydrocharged Hydrocharged left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Not too sure on the derived comment/grouping for the type, but I like everything else

server/analyzer/init.go Show resolved Hide resolved
server/analyzer/validate_create_table.go Show resolved Hide resolved
server/analyzer/validate_create_table.go Outdated Show resolved Hide resolved
server/analyzer/validate_create_table.go Outdated Show resolved Hide resolved
server/types/type.go Outdated Show resolved Hide resolved
server/types/type.go Show resolved Hide resolved
@Hydrocharged
Copy link
Collaborator

I just realized you said two things in your PR message before listing three 💀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants