BUG #1398: Delete takes a long time & explain disagrees with \timing

Поиск
Список
Период
Сортировка
Искать

BUG #1398: Delete takes a long time & explain disagrees with \timing

От:
"Karl Martindale" <karl@cyber.com.au>
Дата:
The following bug has been logged online:

Bug reference:      1398
Logged by:          Karl Martindale
Email address:      karl@cyber.com.au
PostgreSQL version: 7.4.6
Operating system:   Slackware 9.0 - Linux version 2.4.26 (root@tree) (gcc
version 3.3.4)
Description:        Delete takes a long time & explain disagrees with
\timing
Details: 

Deletes from this particular table take a long time (~5 min for 6000rows)

This seems to occur regardless of whether the db has been vacuumed analysed
or both.

The machine is a 2.4GHz P4 w/1Gb RAM

This post is on the recommendation of the highly esteemed folk on
#postgresql on irc.freenode.

In summary this is what I get on my DB:

analyze DELETE FROM "Stock" WHERE "StockID">76045;
                                                         QUERY PLAN
----------------------------------------------------------------------------
-------------------------------------------------
 Index Scan using "PK_Stock" on "Stock"  (cost=0.00..849.44 rows=3241
width=6) (actual time=3.971..19.219 rows=6000 loops=1)
   Index Cond: ("StockID" > 76045)
 Total runtime: 44.438 ms
(3 rows)

Time: 250402.550 ms

---------------------------

Demonstration DB Dump follows:  Actual DB has more foriegn keys into "Stock"
(on "StockID")
-----------------------------------------------
--
-- PostgreSQL database dump
--

SET client_encoding = 'SQL_ASCII';
SET check_function_bodies = false;

SET SESSION AUTHORIZATION 'root';

SET search_path = public, pg_catalog;

--
-- TOC entry 4 (OID 2200)
-- Name: public; Type: ACL; Schema: -; Owner: postgres
--

REVOKE ALL ON SCHEMA public FROM PUBLIC;
GRANT ALL ON SCHEMA public TO PUBLIC;


SET SESSION AUTHORIZATION 'root';

--
-- TOC entry 32 (OID 669694)
-- Name: Stock; Type: TABLE; Schema: public; Owner: root
--

CREATE TABLE "Stock" (
    "StockID" serial NOT NULL,
    "Description" character varying(50) DEFAULT ''::character varying NOT
NULL,
    "OrderTrigger" integer DEFAULT 0 NOT NULL,
    "Active" boolean DEFAULT true NOT NULL,
    "PackSize" integer DEFAULT 1 NOT NULL,
    "Discountable" boolean DEFAULT true NOT NULL,
    "DispenseItem" boolean DEFAULT false NOT NULL,
    "CompanionMessage" character varying(50) DEFAULT ''::character varying
NOT NULL,
    "AutoLabel" boolean DEFAULT false NOT NULL,
    "LockRetail" boolean DEFAULT false NOT NULL,
    "PricePoint" boolean DEFAULT false NOT NULL,
    "PoleDisplay" boolean DEFAULT true NOT NULL,
    "Note" character varying(1500) DEFAULT ''::character varying NOT NULL,
    "ChildID" integer DEFAULT -1 NOT NULL,
    "ChildQty" integer DEFAULT 0 NOT NULL,
    "UnitID" integer DEFAULT -1 NOT NULL,
    "UnitQty" integer DEFAULT 1 NOT NULL,
    "SizeDescription" character varying(100) DEFAULT 'UNIT'::character
varying NOT NULL,
    "MinStockHolding" integer DEFAULT 0 NOT NULL,
    "LogActionID" integer,
    "Hirable" boolean DEFAULT false NOT NULL,
    "OrderableItem" boolean DEFAULT true NOT NULL,
    "SellableItem" boolean DEFAULT true NOT NULL,
    "Clearance" boolean DEFAULT false NOT NULL,
    "DepartmentID" integer DEFAULT -1 NOT NULL,
    "AverageCost" numeric DEFAULT 0.00001 NOT NULL,
    "Markup" numeric DEFAULT 0 NOT NULL,
    "RetailPrice" numeric DEFAULT 0 NOT NULL,
    "GSTPaid" numeric DEFAULT 10 NOT NULL,
    "GSTCharged" numeric DEFAULT 10 NOT NULL,
    "DefaultMarkup" numeric DEFAULT 0 NOT NULL,
    "LastBuyCost" numeric DEFAULT 0 NOT NULL,
    "ManufacturerID" integer,
    "Location" character varying(20) DEFAULT 0 NOT NULL
);


--
-- TOC entry 40 (OID 669730)
-- Name: APN; Type: TABLE; Schema: public; Owner: root
--

CREATE TABLE "APN" (
    "StockID" integer NOT NULL,
    "APN" character varying(50) DEFAULT ''::character varying NOT NULL
);


--
-- TOC entry 42 (OID 669746)
-- Name: SupplierPricing; Type: TABLE; Schema: public; Owner: root
--

CREATE TABLE "SupplierPricing" (
    "SupplierID" integer NOT NULL,
    "StockID" integer NOT NULL,
    "Quantity" smallint DEFAULT 0 NOT NULL,
    "Price" numeric DEFAULT 0 NOT NULL
);


--
-- TOC entry 45 (OID 669755)
-- Name: Supplier; Type: TABLE; Schema: public; Owner: root
--

CREATE TABLE "Supplier" (
    "SupplierID" integer DEFAULT
nextval('public."Supplier_SupplierID_seq"'::text) NOT NULL,
    "Name" character varying(30) DEFAULT ''::character varying NOT NULL,
    "Address" character varying(50) DEFAULT ''::character varying NOT NULL,
    "SuburbID" integer,
    "Phone" character varying(15) DEFAULT ''::character varying NOT NULL,
    "Fax" character varying(15) DEFAULT ''::character varying NOT NULL,
    "Data" character varying(15) DEFAULT ''::character varying NOT NULL,
    "Email" character varying(50) DEFAULT ''::character varying NOT NULL,
    "WebSite" character varying(50) DEFAULT ''::character varying NOT NULL,
    "Memo" character varying(1500) DEFAULT ''::character varying NOT NULL,
    "EDI" boolean DEFAULT false NOT NULL
);


--
-- TOC entry 46 (OID 669768)
-- Name: SupplierStock; Type: TABLE; Schema: public; Owner: root
--

CREATE TABLE "SupplierStock" (
    "SupplierID" integer NOT NULL,
    "StockID" integer NOT NULL,
    "SystemGeneratedOrder" boolean DEFAULT true NOT NULL,
    "MinOrder" integer DEFAULT 0 NOT NULL,
    "RRP" numeric,
    "PDENumber" bigint
) WITHOUT OIDS;


--
-- TOC entry 67 (OID 684946)
-- Name: dev_ri; Type: VIEW; Schema: public; Owner: root
--

CREATE VIEW dev_ri AS
    SELECT t.oid AS trigoid, c.relname AS trig_tbl, t.tgfoid, f.proname AS
trigfunc, t.tgenabled, t.tgconstrname, c2.relname AS const_tbl,
t.tgdeferrable, t.tginitdeferred FROM pg_trigger t, pg_class c, pg_class c2,
pg_proc f WHERE ((((t.tgrelid = c.oid) AND (t.tgconstrrelid = c2.oid)) AND
(t.tgfoid = f.oid)) AND (t.tgname ~ '^RI_'::text)) ORDER BY t.oid;

--
-- TOC entry 7 (OID 717717)
-- Name: Supplier_SupplierID_seq; Type: SEQUENCE; Schema: public; Owner:
root
--

CREATE SEQUENCE "Supplier_SupplierID_seq"
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


--
-- Data for TOC entry 3 (OID 2137930)
-- Name: Stock; Type: TABLE DATA; Schema: public; Owner: root
--

COPY "Stock" ("StockID", "Description", "OrderTrigger", "Active",
"PackSize", "Discountable", "DispenseItem", "CompanionMessage", "AutoLabel",
"LockRetail", "PricePoint", "PoleDisplay", "Note", "ChildID", "ChildQty",
"UnitID", "UnitQty", "SizeDescription", "MinStockHolding", "LogActionID",
"Hirable", "OrderableItem", "SellableItem", "Clearance", "DepartmentID",
"AverageCost", "Markup", "RetailPrice", "GSTPaid", "GSTCharged",
"DefaultMarkup", "LastBuyCost", "ManufacturerID", "Location") FROM stdin;
76044	The Age
Newspaper	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	0	f	t	t	f	-1	0.00001	0	0	10	1
0	0	0	3	0
76045	Couriers
Please	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	0	f	t	t	f	-1	0.00001	0	0	10	10	0
	0	3	0
-1		0	t	1	t	f		f	f	f	t		0	0	0	1	UNIT	0	0	f	t	t	f	0	0.00001	0	0	10	10	0	0	\N	
0
1	Deep Heat	0	t	123	t	t	dog cat	t	t	t	t	notes
here	3	0	0	1	UNIT	0	0	f	t	t	f	4	0.00001	0	0	10	10	0	0	\N	0
2	KY BIG
Tube	0	t	1	t	f		f	f	f	t		0	0	0	1	UNIT	0	0	f	t	t	f	2	0.00001	0	0	10	10	0	0	\N
	0
6	Huggies Girls
Nappies	0	t	1	t	f		f	f	f	t		0	0	0	1	UNIT	0	0	f	t	t	f	6	0.00001	0	0	10	10	0	0
	\N	0
3	5
Frangers	0	t	1	t	f		f	f	f	t		0	0	0	1	UNIT	0	0	f	t	t	f	3	0.00001	0	0	10	10	0	
0	\N	0
4	10
Frangers	0	t	1	t	f		f	f	f	t		0	0	0	1	UNIT	0	0	f	t	t	f	3	0.00001	0	0	10	10	0	
0	\N	0
5	Huggies Boys
Nappies	0	t	345	t	f	blah	f	f	f	t		0	0	0	1	UNIT	4	0	f	t	t	f	5	0.00001	0	0	10	
10	0	0	\N	0
0	KY Little
Tube	0	t	1	t	f		f	f	f	t		0	0	0	1	UNIT	123	0	f	t	t	f	2	0.00001	0	123	1	10	0	0
	\N	0
415089	ZOCOR TAB 80MG
30	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	
0	3	06P46
415090	ZOFF ADH PLASTER REMOVER
250ML	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10
	5000	0	3	31Y36
415091	ZOFRAN P/AMP  4MG/2ML 
1	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	0
	3	46C06
415092	ZOFRAN P/AMP  4MG/2ML 
5	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	0
	3	44I04
415093	ZOFRAN P/AMP  8MG/4ML 
1	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	0
	3	45F09
415094	ZOFRAN TAB 4MG 
4	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	0
	3	61H63
415095	ZOFRAN TAB 4MG
10	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	
0	3	42761
415096	ZOFRAN TAB 8MG 
4	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	0
	3	73Y21
415097	ZOFRAN TAB 8MG
10	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	
0	3	65Y33
415098	ZOFRAN ZYDIS WAFER  4MG  
4	0	t	1	t	f		f	f	f	t		-1	0	-1	0	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	0
	3	43943
415099	ZOFRAN ZYDIS WAFER  4MG 
10	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	
0	3	43273
415100	ZOFRAN ZYDIS WAFER  8MG  
4	0	t	1	t	f		f	f	f	t		-1	0	-1	0	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	0
	3	40951
415101	ZOFRAN ZYDIS WAFER  8MG 
10	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	
0	3	45171
415102	ZOLADEX SAFESYSTM  3.6MG
DEPOT	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10
	0	0	3	06C95
415103	ZOLADEX SAFESYSTM 10.8MG
DEPOT	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10
	0	0	3	06B51
415104	ZOLOFT TAB 100MG
30	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	
0	3	56A32
415105	ZOLOFT TAB 50MG 
30	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	
0	3	06I54
415106	ZOMETA 4MG/5ML LIQ VIAL 
S100	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	
0	0	3	41A00
415107	ZOMIG TAB 2.5MG 
2	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	0
	3	04X65
415108	ZOTON CAP 15MG 
30	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	
0	3	75W62
415109	ZOTON CAP 30MG 
30	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	
0	3	68A21
415110	ZOTON SUSP  30MG  28
SACHETS	0	t	1	t	f		f	f	f	t		-1	0	-1	0	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	
10	0	0	3	67K44
415111	ZOVIRAX COLD SORE CRM 2G
PUMP	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	
5000	0	3	69G51
415112	ZOVIRAX COLD SORE CRM 2G
TUBE	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	
5000	0	3	69T33
415113	ZOVIRAX OPHTHALMIC OINT
4.5G	0	t	1	t	f		f	f	f	t		-1	0	-1	0	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	
0	0	3	04U36
415114	ZOVIRAX TAB 200MG  25
DISPERS	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	
10	0	0	3	04X22
415115	ZOVIRAX TAB 200MG  90
DISPERS	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	
10	0	0	3	39D12
415116	ZOVIRAX TAB 800MG  35
DISPERS	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	
10	0	0	3	39X58
415117	ZOVIRAX TAB 800MG
120	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0
	0	3	43A07
415118	ZSC DUSTING POWDER 
100G	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	
6100	0	3	06S31
415119	ZUMENON TAB 2MG
56	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	
0	3	42553
415120	ZYBAN TAB 150MG 
30	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	
0	3	71B42
415121	ZYBAN TAB 150MG 
90	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	
0	3	77B21
415122	ZYDOL CAP  50MG 
20	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	
0	3	67L52
415123	ZYDOL SR TAB 100MG
20	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	
0	3	63Q22
415124	ZYDOL SR TAB 150MG
20	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	
0	3	65E13
415125	ZYDOL SR TAB 200MG
20	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	
0	3	65Q43
415126	ZYLOPRIM TAB 100MG
200	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0
	0	3	29N53
415127	ZYLOPRIM TAB 300MG 
60	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	
0	3	02M23
415128	ZYPREXA TAB  2.5MG 
30	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	
0	3	04X57
415129	ZYPREXA TAB  5.0MG 
30	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	
0	3	70A23
415130	ZYPREXA TAB  7.5MG 
30	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	
0	3	04A36
415131	ZYPREXA TAB 10.0MG 
30	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	
0	3	04J34
415132	ZYPREXA ZYDIS WAFER  5.0MG 
28	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	
0	3	75Z22
415133	ZYPREXA ZYDIS WAFER 10.0MG 
28	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	0	
0	3	35H33
415134	ZYRTEC DROPS 10MG/ML 20ML
BTTL	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	
6666	0	3	73M61
415135	ZYRTEC PLUS DECONG TAB 
10	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	66
66	0	3	04P36
415136	ZYRTEC SOLN 1MG/ML  75ML
BTTL	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	
6666	0	3	35H44
415137	ZYRTEC SOLN 1MG/ML 200ML
BTTL	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	
6666	0	3	35M52
415138	ZYRTEC TAB 10MG
10	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	66
66	0	3	04Y47
415139	ZYRTEC TAB 10MG
30	0	t	1	t	f		f	f	f	t		-1	0	-1	1	UNIT	0	\N	f	t	t	f	-1	0.00001	0	0	1000	10	66
66	0	3	04H57
\.



--
-- Data for TOC entry 160 (OID 669730)
-- Name: APN; Type: TABLE DATA; Schema: public; Owner: root
--

COPY "APN" ("StockID", "APN") FROM stdin;
76044	9770312630042
76045	150102154273
\.


--
-- Data for TOC entry 162 (OID 669746)
-- Name: SupplierPricing; Type: TABLE DATA; Schema: public; Owner: root
--

COPY "SupplierPricing" ("SupplierID", "StockID", "Quantity", "Price") FROM
stdin;
3	76044	1	1.2
3	76045	1	6.5
\.


--
-- Data for TOC entry 163 (OID 669755)
-- Name: Supplier; Type: TABLE DATA; Schema: public; Owner: root
--

COPY "Supplier" ("SupplierID", "Name", "Address", "SuburbID", "Phone",
"Fax", "Data", "Email", "WebSite", "Memo", "EDI") FROM stdin;
3	Sigma		0							f
\.


--
-- Data for TOC entry 164 (OID 669768)
-- Name: SupplierStock; Type: TABLE DATA; Schema: public; Owner: root
--

COPY "SupplierStock" ("SupplierID", "StockID", "SystemGeneratedOrder",
"MinOrder", "RRP", "PDENumber") FROM stdin;
3	76045	t	1	6.50	985623
3	76044	t	50	1.20	985421
\.


--
-- TOC entry 103 (OID 978593)
-- Name: IDX_Stock_StockID; Type: INDEX; Schema: public; Owner: root
--

CREATE INDEX "IDX_Stock_StockID" ON "Stock" USING btree ("StockID");


--
-- TOC entry 104 (OID 669728)
-- Name: PK_Stock; Type: CONSTRAINT; Schema: public; Owner: root
--

ALTER TABLE ONLY "Stock"
    ADD CONSTRAINT "PK_Stock" PRIMARY KEY ("StockID");


--
-- TOC entry 106 (OID 669733)
-- Name: PK_APN; Type: CONSTRAINT; Schema: public; Owner: root
--

ALTER TABLE ONLY "APN"
    ADD CONSTRAINT "PK_APN" PRIMARY KEY ("StockID", "APN");

--
-- Name: PK_Suppliers; Type: CONSTRAINT; Schema: public; Owner: root
--

ALTER TABLE ONLY "Supplier"
    ADD CONSTRAINT "PK_Suppliers" PRIMARY KEY ("SupplierID");


--
-- TOC entry 204 (OID 670023)
-- Name: FK_SupplierPricing_StockID; Type: FK CONSTRAINT; Schema: public;
Owner: root
--

ALTER TABLE ONLY "SupplierPricing"
    ADD CONSTRAINT "FK_SupplierPricing_StockID" FOREIGN KEY ("StockID")
REFERENCES "Stock"("StockID") ON DELETE RESTRICT;


--
-- TOC entry 205 (OID 670027)
-- Name: FK_SupplierPricing_SupplierID; Type: FK CONSTRAINT; Schema: public;
Owner: root
--

ALTER TABLE ONLY "SupplierPricing"
    ADD CONSTRAINT "FK_SupplierPricing_SupplierID" FOREIGN KEY
("SupplierID") REFERENCES "Supplier"("SupplierID") ON DELETE RESTRICT;


--
-- TOC entry 207 (OID 670031)
-- Name: FK_SupplierStock_SupplierID; Type: FK CONSTRAINT; Schema: public;
Owner: root
--

ALTER TABLE ONLY "SupplierStock"
    ADD CONSTRAINT "FK_SupplierStock_SupplierID" FOREIGN KEY ("SupplierID")
REFERENCES "Supplier"("SupplierID") ON DELETE RESTRICT;


--
-- TOC entry 208 (OID 670035)
-- Name: FK_SupplierStock_StockID; Type: FK CONSTRAINT; Schema: public;
Owner: root
--

ALTER TABLE ONLY "SupplierStock"
    ADD CONSTRAINT "FK_SupplierStock_StockID" FOREIGN KEY ("StockID")
REFERENCES "Stock"("StockID") ON DELETE RESTRICT;


--
-- TOC entry 202 (OID 960505)
-- Name: FK_Stock_ManufacturerID; Type: FK CONSTRAINT; Schema: public;
Owner: root
--

ALTER TABLE ONLY "Stock"
    ADD CONSTRAINT "FK_Stock_ManufacturerID" FOREIGN KEY ("ManufacturerID")
REFERENCES "Supplier"("SupplierID") ON DELETE RESTRICT;


--
-- TOC entry 77 (OID 669692)
-- Name: Stock_StockID_seq; Type: SEQUENCE SET; Schema: public; Owner: root
--

SELECT pg_catalog.setval('"Stock_StockID_seq"', 384986, true);


--

SELECT pg_catalog.setval('"Supplier_SupplierID_seq"', 4531, true);


SET SESSION AUTHORIZATION 'postgres';

--
-- TOC entry 3 (OID 2200)
-- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: postgres
--

COMMENT ON SCHEMA public IS 'Standard public schema';


SET SESSION AUTHORIZATION 'root';

Re: BUG #1398: Delete takes a long time & explain disagrees with \timing

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"Karl Martindale"  writes:
> Deletes from this particular table take a long time (~5 min for 6000rows)

This usually occurs when you have another table with a foreign key
reference to this one, and the referencing column either has no index or
isn't of the exact same datatype as the referenced column.  The FK
checks then are forced to use sequential scans instead of index probes
:-(

			regards, tom lane
FAQ