Обсуждение: Performance difference between char and int2 columns
hi everybody.
i have two table as :
CREATE TABLE "public"."tb_section_phones" (
"section_id" INTEGER NOT NULL,
"ptype_id" INTEGER NOT NULL,
"country_code" SMALLINT DEFAULT 90,
"domain_code" SMALLINT,
"number" CHAR(7) NOT NULL,
"extension" VARCHAR(6),
CONSTRAINT "tb_section_phones_fk" FOREIGN KEY ("section_id")
REFERENCES "public"."tb_sections"("sect_id")
ON DELETE CASCADE
ON UPDATE CASCADE
NOT DEFERRABLE,
CONSTRAINT "tb_section_phones_fk1" FOREIGN KEY ("ptype_id")
REFERENCES "public"."tb_phone_types"("ptype_id")
ON DELETE CASCADE
ON UPDATE CASCADE
NOT DEFERRABLE
) WITHOUT OIDS;
"section_id" INTEGER NOT NULL,
"ptype_id" INTEGER NOT NULL,
"country_code" SMALLINT DEFAULT 90,
"domain_code" SMALLINT,
"number" CHAR(7) NOT NULL,
"extension" VARCHAR(6),
CONSTRAINT "tb_section_phones_fk" FOREIGN KEY ("section_id")
REFERENCES "public"."tb_sections"("sect_id")
ON DELETE CASCADE
ON UPDATE CASCADE
NOT DEFERRABLE,
CONSTRAINT "tb_section_phones_fk1" FOREIGN KEY ("ptype_id")
REFERENCES "public"."tb_phone_types"("ptype_id")
ON DELETE CASCADE
ON UPDATE CASCADE
NOT DEFERRABLE
) WITHOUT OIDS;
CREATE TABLE "public"."tb_section_phones_temp" (
"sect_id" INTEGER NOT NULL,
"ptype_id" INTEGER NOT NULL,
"country_code" CHAR(2) DEFAULT 90,
"domain_code" CHAR(3),
"number" CHAR(7) NOT NULL,
"extension" VARCHAR(6),
CONSTRAINT "tb_section_phones_fk" FOREIGN KEY ("sect_id")
REFERENCES "public"."tb_sections"("sect_id")
ON DELETE CASCADE
ON UPDATE CASCADE
NOT DEFERRABLE,
CONSTRAINT "tb_section_phones_fk2" FOREIGN KEY ("ptype_id")
REFERENCES "public"."tb_phone_types"("ptype_id")
ON DELETE CASCADE
ON UPDATE CASCADE
NOT DEFERRABLE
) WITHOUT OIDS;
"sect_id" INTEGER NOT NULL,
"ptype_id" INTEGER NOT NULL,
"country_code" CHAR(2) DEFAULT 90,
"domain_code" CHAR(3),
"number" CHAR(7) NOT NULL,
"extension" VARCHAR(6),
CONSTRAINT "tb_section_phones_fk" FOREIGN KEY ("sect_id")
REFERENCES "public"."tb_sections"("sect_id")
ON DELETE CASCADE
ON UPDATE CASCADE
NOT DEFERRABLE,
CONSTRAINT "tb_section_phones_fk2" FOREIGN KEY ("ptype_id")
REFERENCES "public"."tb_phone_types"("ptype_id")
ON DELETE CASCADE
ON UPDATE CASCADE
NOT DEFERRABLE
) WITHOUT OIDS;
the differences between two table are :
in the first table country_code type is smallint, in the second table char(2)
in the first table domain_code type is smallint, in the second table char(3)
.
The problem is that:
my both table has 10 records.
when i run this query on first table :
select * from tb_section_phones;
it lasts 0.02 sec.
when i run this query on second table :
select * from tb_section_phones_temp;
it lasts 0.13 sec.
6.5 times slower.
why so performance difference?
should i prefer int as column type?
thanks in advance.
Yavuz Kavus wrote:
> hi everybody.
> The problem is that:
> my both table has 10 records.
> when i run this query on first table :
> select * from tb_section_phones;
> it lasts 0.02 sec.
> when i run this query on second table :
> select * from tb_section_phones_temp;
> it lasts 0.13 sec.
>
> 6.5 times slower.
> why so performance difference?
> should i prefer int as column type?
Did you ANALYZE your tables?
What version of Postgres is this?
--
Alban Hertroys
alban@magproductions.nl
magproductions b.v.
T: ++31(0)534346874
F: ++31(0)534346876
M:
I: www.magproductions.nl
A: Postbus 416
7500 AK Enschede
// Integrate Your World //