Re: Slow query, possibly not using index

2023-08-27 Thread Les
> > > > > I'm aware of the problems with random UUID values. I was using this > > function to create ulids from the beginning: > > Oh, well that would have been useful information to provide at the > outset. I'm sorry, I left this out. > Now that we know the index order is correlated with creatio

Re: Slow query, possibly not using index

2023-08-27 Thread Tom Lane
Les writes: >>> If I try to select a single unused block this way: >>> explain analyze select id from media.block b where nrefs =0 limit 1 >>> then it runs for more than 10 minutes (I'm not sure how long, I cancelled >>> the query after 10 minutes). >> You might think that even so, it shouldn't t

Re: Slow query, possibly not using index

2023-08-27 Thread Wael Khobalatte
> Nobody ever deleted anything from this table. Since it was created, this has been a write-only table. does write-only include updates? that would create the dead rows tom is referring to. > I believe it is not actually using the index, because reading a single (random?) entry from an index shou

Re: Slow query, possibly not using index

2023-08-27 Thread Les
> > If I try to select a single unused block this way: > > explain analyze select id from media.block b where nrefs =0 limit 1 > > then it runs for more than 10 minutes (I'm not sure how long, I cancelled > > the query after 10 minutes). > > Are you sure it isn't blocked on a lock? > Yes, I'm sure

Re: Slow query, possibly not using index

2023-08-27 Thread Tom Lane
Les writes: > If I try to select a single unused block this way: > explain analyze select id from media.block b where nrefs =0 limit 1 > then it runs for more than 10 minutes (I'm not sure how long, I cancelled > the query after 10 minutes). Are you sure it isn't blocked on a lock? Another theor

Slow query, possibly not using index

2023-08-27 Thread Les
I have this table: CREATE TABLE media.block ( id uuid NOT NULL, "size" int8 NOT NULL, nrefs int8 NOT NULL DEFAULT 0, block bytea NOT NULL, hs256 bytea NOT NULL, CONSTRAINT block_pkey PRIMARY KEY (id), CONSTRAINT chk_nrefs CHECK ((nrefs >= 0)) ) WITH ( toast_tuple_target=8160 ) TABLESPA