Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Virtual" means never knowing where your next byte is coming from.


computers / comp.sys.tandem / Re: sql cost changing from day to day

SubjectAuthor
* sql cost changing from day to dayMemmedaga Memmedov
`* Re: sql cost changing from day to dayRandall
 `* Re: sql cost changing from day to dayKeith Dick
  `- Re: sql cost changing from day to dayRandall

1
sql cost changing from day to day

<844794d2-9076-4ac3-b7c8-407b0a12123fn@googlegroups.com>

  copy mid

https://www.novabbs.com/computers/article-flat.php?id=552&group=comp.sys.tandem#552

  copy link   Newsgroups: comp.sys.tandem
X-Received: by 2002:a05:6214:1d01:b0:4b0:b782:15a6 with SMTP id e1-20020a0562141d0100b004b0b78215a6mr752566qvd.43.1664519331809;
Thu, 29 Sep 2022 23:28:51 -0700 (PDT)
X-Received: by 2002:a25:cc0d:0:b0:6bc:facb:7f1b with SMTP id
l13-20020a25cc0d000000b006bcfacb7f1bmr912582ybf.47.1664519331533; Thu, 29 Sep
2022 23:28:51 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.sys.tandem
Date: Thu, 29 Sep 2022 23:28:51 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=185.220.152.249; posting-account=nVVCRgoAAACrQkyRv5XcWnnembs0sPhF
NNTP-Posting-Host: 185.220.152.249
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <844794d2-9076-4ac3-b7c8-407b0a12123fn@googlegroups.com>
Subject: sql cost changing from day to day
From: mkele...@gmail.com (Memmedaga Memmedov)
Injection-Date: Fri, 30 Sep 2022 06:28:51 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3917
 by: Memmedaga Memmedov - Fri, 30 Sep 2022 06:28 UTC

Hi,
You can understand my problem from subject; "sql cost changing from day to day"
I have a sql statement in cobol program. Yesterday sqlcost was 1030, today is 117. So my programs sometimes run slowly.
I will share two outputs of explain comments. What is the reason? Thanks.
TABLEID has 2 primary key, ID and CUSTOMER.
TABLEID has index ID and DATE.

>>explain
+>select * from =TABLEID
+>where ID=12345678912
+>browse access;

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Query plan 1
SQL request : Select
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

------------------------------------------------------------------------------
Plan step 1
------------------------------------------------------------------------------

Operation 1.0 : Scan
Table : \SYS1.$DISK1.SUBVOL.TABLEID
with correlation name TABLEID
Access type : No locks, browse access
Lock mode : Chosen by the system
Column processing : Requires retrieval of 50 out of 50 columns

Access path 1 : Alternate \SYS1.$DISK1.SUBVOL.INDEX1, sequential cache
SBB for reads : Virtual, double buffer
Begin key pred. : ID = 12345678912
End key pred. : ID = 12345678912
Index selectivity : Expect to examine 0.0035% of rows from index
Index pred. : None
Base table pred. : None

Executor pred. : None
Table selectivity : Expect to select 0.0035% of rows from table
Expected row count: 335 rows after the scan
Operation cost : 1030

Total cost : 1030
>>

>>explain
+>select * from =TABLEID
+>where ID=12345678912
+>browse access;

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Query plan 1
SQL request : Select
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

-----------------------------------------------------------------------------
Plan step 1
-----------------------------------------------------------------------------

Operation 1.0 : Scan
Table : \SYS1.$DISK1.SUBVOL.TABLEID
with correlation name TABLEID
Access type : No locks, browse access
Lock mode : Chosen by the system
Column processing : Requires retrieval of 50 out of 50 columns

Access path 1 : Alternate \SYS1.$DISK1.SUBVOL.INDEX1
SBB for reads : Real
Begin key pred. : ID = 12345678912
End key pred. : ID = 12345678912
Index selectivity : Expect to examine 0.0004% of rows from index
Index pred. : None
Base table pred. : None

Executor pred. : None
Table selectivity : Expect to select 0.0004% of rows from table
Expected row count: 37 rows after the scan
Operation cost : 117

Total cost : 117
>>

Re: sql cost changing from day to day

<52a27921-1347-4e8f-b209-6f079d324a17n@googlegroups.com>

  copy mid

https://www.novabbs.com/computers/article-flat.php?id=554&group=comp.sys.tandem#554

  copy link   Newsgroups: comp.sys.tandem
X-Received: by 2002:a05:622a:190:b0:35d:4803:4303 with SMTP id s16-20020a05622a019000b0035d48034303mr8042206qtw.253.1664566733531;
Fri, 30 Sep 2022 12:38:53 -0700 (PDT)
X-Received: by 2002:a05:6902:1142:b0:6af:61be:ab53 with SMTP id
p2-20020a056902114200b006af61beab53mr10494109ybu.118.1664566733343; Fri, 30
Sep 2022 12:38:53 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.sys.tandem
Date: Fri, 30 Sep 2022 12:38:53 -0700 (PDT)
In-Reply-To: <844794d2-9076-4ac3-b7c8-407b0a12123fn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2607:fea8:3fa6:b400:5c4f:8220:317e:21ec;
posting-account=6VebZwoAAAAgrpUtsowyjrKRLNlqxnXo
NNTP-Posting-Host: 2607:fea8:3fa6:b400:5c4f:8220:317e:21ec
References: <844794d2-9076-4ac3-b7c8-407b0a12123fn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <52a27921-1347-4e8f-b209-6f079d324a17n@googlegroups.com>
Subject: Re: sql cost changing from day to day
From: rsbec...@nexbridge.com (Randall)
Injection-Date: Fri, 30 Sep 2022 19:38:53 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 4262
 by: Randall - Fri, 30 Sep 2022 19:38 UTC

On Friday, September 30, 2022 at 2:28:52 a.m. UTC-4, Memmedaga Memmedov wrote:
> Hi,
> You can understand my problem from subject; "sql cost changing from day to day"
> I have a sql statement in cobol program. Yesterday sqlcost was 1030, today is 117. So my programs sometimes run slowly.
> I will share two outputs of explain comments. What is the reason? Thanks.
> TABLEID has 2 primary key, ID and CUSTOMER.
> TABLEID has index ID and DATE.
>
> >>explain
> +>select * from =TABLEID
> +>where ID=12345678912
> +>browse access;
>
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> Query plan 1
> SQL request : Select
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>
> ------------------------------------------------------------------------------
> Plan step 1
> ------------------------------------------------------------------------------
>
> Operation 1.0 : Scan
> Table : \SYS1.$DISK1.SUBVOL.TABLEID
> with correlation name TABLEID
> Access type : No locks, browse access
> Lock mode : Chosen by the system
> Column processing : Requires retrieval of 50 out of 50 columns
>
> Access path 1 : Alternate \SYS1.$DISK1.SUBVOL.INDEX1, sequential cache
> SBB for reads : Virtual, double buffer
> Begin key pred. : ID = 12345678912
> End key pred. : ID = 12345678912
> Index selectivity : Expect to examine 0.0035% of rows from index
> Index pred. : None
> Base table pred. : None
>
> Executor pred. : None
> Table selectivity : Expect to select 0.0035% of rows from table
> Expected row count: 335 rows after the scan
> Operation cost : 1030
>
> Total cost : 1030
> >>
>
> >>explain
> +>select * from =TABLEID
> +>where ID=12345678912
> +>browse access;
>
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> Query plan 1
> SQL request : Select
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>
> -----------------------------------------------------------------------------
> Plan step 1
> -----------------------------------------------------------------------------
>
> Operation 1.0 : Scan
> Table : \SYS1.$DISK1.SUBVOL.TABLEID
> with correlation name TABLEID
> Access type : No locks, browse access
> Lock mode : Chosen by the system
> Column processing : Requires retrieval of 50 out of 50 columns
>
> Access path 1 : Alternate \SYS1.$DISK1.SUBVOL.INDEX1
> SBB for reads : Real
> Begin key pred. : ID = 12345678912
> End key pred. : ID = 12345678912
> Index selectivity : Expect to examine 0.0004% of rows from index
> Index pred. : None
> Base table pred. : None
>
> Executor pred. : None
> Table selectivity : Expect to select 0.0004% of rows from table
> Expected row count: 37 rows after the scan
> Operation cost : 117
>
> Total cost : 117
> >>

How often do you update statistics? Are the results changing before and after statistics are updated? What is the primary key on the table? Are there statistics on the primary key as well as the index?

Re: sql cost changing from day to day

<a415424e-47f5-4e84-b8be-b84e7fc0a17fn@googlegroups.com>

  copy mid

https://www.novabbs.com/computers/article-flat.php?id=556&group=comp.sys.tandem#556

  copy link   Newsgroups: comp.sys.tandem
X-Received: by 2002:ac8:5dcd:0:b0:35c:e209:39e7 with SMTP id e13-20020ac85dcd000000b0035ce20939e7mr9747679qtx.651.1664602639961;
Fri, 30 Sep 2022 22:37:19 -0700 (PDT)
X-Received: by 2002:a25:b78d:0:b0:6ad:bdc3:a47b with SMTP id
n13-20020a25b78d000000b006adbdc3a47bmr11379754ybh.358.1664602639756; Fri, 30
Sep 2022 22:37:19 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.sys.tandem
Date: Fri, 30 Sep 2022 22:37:19 -0700 (PDT)
In-Reply-To: <52a27921-1347-4e8f-b209-6f079d324a17n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=98.42.228.104; posting-account=Lua_ZwoAAADivbVXQF8uKE7dZSUNm9vj
NNTP-Posting-Host: 98.42.228.104
References: <844794d2-9076-4ac3-b7c8-407b0a12123fn@googlegroups.com> <52a27921-1347-4e8f-b209-6f079d324a17n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a415424e-47f5-4e84-b8be-b84e7fc0a17fn@googlegroups.com>
Subject: Re: sql cost changing from day to day
From: rkd...@gmail.com (Keith Dick)
Injection-Date: Sat, 01 Oct 2022 05:37:19 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 8392
 by: Keith Dick - Sat, 1 Oct 2022 05:37 UTC

On Friday, September 30, 2022 at 12:38:54 PM UTC-7, Randall wrote:
> On Friday, September 30, 2022 at 2:28:52 a.m. UTC-4, Memmedaga Memmedov wrote:
> > Hi,
> > You can understand my problem from subject; "sql cost changing from day to day"
> > I have a sql statement in cobol program. Yesterday sqlcost was 1030, today is 117. So my programs sometimes run slowly.
> > I will share two outputs of explain comments. What is the reason? Thanks.
> > TABLEID has 2 primary key, ID and CUSTOMER.
> > TABLEID has index ID and DATE.
> >
> > >>explain
> > +>select * from =TABLEID
> > +>where ID=12345678912
> > +>browse access;
> >
> > <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> > Query plan 1
> > SQL request : Select
> > <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> >
> > ------------------------------------------------------------------------------
> > Plan step 1
> > ------------------------------------------------------------------------------
> >
> > Operation 1.0 : Scan
> > Table : \SYS1.$DISK1.SUBVOL.TABLEID
> > with correlation name TABLEID
> > Access type : No locks, browse access
> > Lock mode : Chosen by the system
> > Column processing : Requires retrieval of 50 out of 50 columns
> >
> > Access path 1 : Alternate \SYS1.$DISK1.SUBVOL.INDEX1, sequential cache
> > SBB for reads : Virtual, double buffer
> > Begin key pred. : ID = 12345678912
> > End key pred. : ID = 12345678912
> > Index selectivity : Expect to examine 0.0035% of rows from index
> > Index pred. : None
> > Base table pred. : None
> >
> > Executor pred. : None
> > Table selectivity : Expect to select 0.0035% of rows from table
> > Expected row count: 335 rows after the scan
> > Operation cost : 1030
> >
> > Total cost : 1030
> > >>
> >
> > >>explain
> > +>select * from =TABLEID
> > +>where ID=12345678912
> > +>browse access;
> >
> > <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> > Query plan 1
> > SQL request : Select
> > <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> >
> > -----------------------------------------------------------------------------
> > Plan step 1
> > -----------------------------------------------------------------------------
> >
> > Operation 1.0 : Scan
> > Table : \SYS1.$DISK1.SUBVOL.TABLEID
> > with correlation name TABLEID
> > Access type : No locks, browse access
> > Lock mode : Chosen by the system
> > Column processing : Requires retrieval of 50 out of 50 columns
> >
> > Access path 1 : Alternate \SYS1.$DISK1.SUBVOL.INDEX1
> > SBB for reads : Real
> > Begin key pred. : ID = 12345678912
> > End key pred. : ID = 12345678912
> > Index selectivity : Expect to examine 0.0004% of rows from index
> > Index pred. : None
> > Base table pred. : None
> >
> > Executor pred. : None
> > Table selectivity : Expect to select 0.0004% of rows from table
> > Expected row count: 37 rows after the scan
> > Operation cost : 117
> >
> > Total cost : 117
> > >>
> How often do you update statistics? Are the results changing before and after statistics are updated? What is the primary key on the table? Are there statistics on the primary key as well as the index?

I assume that when you wrote "TABLEID has 2 primary key, ID and CUSTOMER", you meant that the primary key contains two columns named ID and CUSTOMER. Is that correct? A table cannot have two primary keys., so I don't know what else you could have meant.

Are the two runs actually accessing the same table? Or is the DEFINE =TABLEID pointing to different tables for the two runs?

Can you tell whether the number of rows accessed from the base table actually are approximately the numbers estimated by the EXPLAIN output (about 335 in one case and about 37 in the other)?

Even if the number of rows accessed is about 335 vs. about 37, I would not expect either program to take enough time to run that you would feel the need to say that one of the runs is slow, unless the program performs an awful lot of work on each row that it accesses. What is the actual run time of the program in the two cases?

I imagine that the value of ID that the two queries are selecting is different in the two jobs, and so it is correct that the number of rows that match the queries are different. Is that true, or are you getting a different number of rows actually selected when you run the same query twice?

I never needed to use EXPLAIN plans very much, so I don't remember very much about interpreting them. But I have a feeling that these plans say that it is using the alternate index on ID rather than the initial part of the primary key (ID, CUSTOMER) in the scan. If the primary key actually is on (CUSTOMER, ID), then that would make sense, since the rows of the base table would not be grouped by ID. That would mean it would scan the index on ID, and for each row of the index that matched the value of ID, it would have to do a random read of the base table, jumping all around the base table rather than being able to sequentially read a subset of rows that are all together from the base table. That random access will make the program run slower than if the base table had ID as the most significant part of the primary key, but even so, it would still only be around 300 random reads from the base table, and that would not take very much longer than 30 or 40 random reads of the base table.

If I had to make a guess based on the incomplete information given here, I would guess that the job that runs enough slower to warrant raising this question is actually accessing a lot more than 300 rows from the base table and has to access them randomly because the primary key does not have ID as its most significant column. The job that runs faster is still doing the random reads, but is accessing a much smaller number of rows. That guess might be wrong, so keep in mind that it is only my guess.

That does not answer the question of why SQL computes a significantly different cost for the query in the two jobs. If my guess that the two jobs are not accessing the same table is not the answer for that part of puzzle, then I'd have to agree with Randall that the difference could have something to do with the statistics on the table, but I don't know enough about the optimizer to guess what is most likely to have gone wrong with the statistics.

If the primary key of the table actually is (ID, CUSTOMER), then I think the plan should not be using the alternate index at all, and the reason it is using the alternate index would need to be addressed. Maybe something gone wrong with the statistics could have caused that, but I don't know enough to say what it could be.

Re: sql cost changing from day to day

<f1934175-660c-4790-b926-b6e586a1b1ddn@googlegroups.com>

  copy mid

https://www.novabbs.com/computers/article-flat.php?id=557&group=comp.sys.tandem#557

  copy link   Newsgroups: comp.sys.tandem
X-Received: by 2002:a05:6214:29ea:b0:4ad:8743:699a with SMTP id jv10-20020a05621429ea00b004ad8743699amr11868707qvb.44.1664652005557;
Sat, 01 Oct 2022 12:20:05 -0700 (PDT)
X-Received: by 2002:a0d:ea90:0:b0:358:b93:d039 with SMTP id
t138-20020a0dea90000000b003580b93d039mr2641861ywe.47.1664652005317; Sat, 01
Oct 2022 12:20:05 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.sys.tandem
Date: Sat, 1 Oct 2022 12:20:05 -0700 (PDT)
In-Reply-To: <a415424e-47f5-4e84-b8be-b84e7fc0a17fn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2607:fea8:3fa6:b400:6020:baf7:458:8190;
posting-account=6VebZwoAAAAgrpUtsowyjrKRLNlqxnXo
NNTP-Posting-Host: 2607:fea8:3fa6:b400:6020:baf7:458:8190
References: <844794d2-9076-4ac3-b7c8-407b0a12123fn@googlegroups.com>
<52a27921-1347-4e8f-b209-6f079d324a17n@googlegroups.com> <a415424e-47f5-4e84-b8be-b84e7fc0a17fn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f1934175-660c-4790-b926-b6e586a1b1ddn@googlegroups.com>
Subject: Re: sql cost changing from day to day
From: rsbec...@nexbridge.com (Randall)
Injection-Date: Sat, 01 Oct 2022 19:20:05 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 9245
 by: Randall - Sat, 1 Oct 2022 19:20 UTC

On Saturday, October 1, 2022 at 1:37:21 a.m. UTC-4, rkd...@gmail.com wrote:
> On Friday, September 30, 2022 at 12:38:54 PM UTC-7, Randall wrote:
> > On Friday, September 30, 2022 at 2:28:52 a.m. UTC-4, Memmedaga Memmedov wrote:
> > > Hi,
> > > You can understand my problem from subject; "sql cost changing from day to day"
> > > I have a sql statement in cobol program. Yesterday sqlcost was 1030, today is 117. So my programs sometimes run slowly.
> > > I will share two outputs of explain comments. What is the reason? Thanks.
> > > TABLEID has 2 primary key, ID and CUSTOMER.
> > > TABLEID has index ID and DATE.
> > >
> > > >>explain
> > > +>select * from =TABLEID
> > > +>where ID=12345678912
> > > +>browse access;
> > >
> > > <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> > > Query plan 1
> > > SQL request : Select
> > > <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> > >
> > > ------------------------------------------------------------------------------
> > > Plan step 1
> > > ------------------------------------------------------------------------------
> > >
> > > Operation 1.0 : Scan
> > > Table : \SYS1.$DISK1.SUBVOL.TABLEID
> > > with correlation name TABLEID
> > > Access type : No locks, browse access
> > > Lock mode : Chosen by the system
> > > Column processing : Requires retrieval of 50 out of 50 columns
> > >
> > > Access path 1 : Alternate \SYS1.$DISK1.SUBVOL.INDEX1, sequential cache
> > > SBB for reads : Virtual, double buffer
> > > Begin key pred. : ID = 12345678912
> > > End key pred. : ID = 12345678912
> > > Index selectivity : Expect to examine 0.0035% of rows from index
> > > Index pred. : None
> > > Base table pred. : None
> > >
> > > Executor pred. : None
> > > Table selectivity : Expect to select 0.0035% of rows from table
> > > Expected row count: 335 rows after the scan
> > > Operation cost : 1030
> > >
> > > Total cost : 1030
> > > >>
> > >
> > > >>explain
> > > +>select * from =TABLEID
> > > +>where ID=12345678912
> > > +>browse access;
> > >
> > > <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> > > Query plan 1
> > > SQL request : Select
> > > <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> > >
> > > -----------------------------------------------------------------------------
> > > Plan step 1
> > > -----------------------------------------------------------------------------
> > >
> > > Operation 1.0 : Scan
> > > Table : \SYS1.$DISK1.SUBVOL.TABLEID
> > > with correlation name TABLEID
> > > Access type : No locks, browse access
> > > Lock mode : Chosen by the system
> > > Column processing : Requires retrieval of 50 out of 50 columns
> > >
> > > Access path 1 : Alternate \SYS1.$DISK1.SUBVOL.INDEX1
> > > SBB for reads : Real
> > > Begin key pred. : ID = 12345678912
> > > End key pred. : ID = 12345678912
> > > Index selectivity : Expect to examine 0.0004% of rows from index
> > > Index pred. : None
> > > Base table pred. : None
> > >
> > > Executor pred. : None
> > > Table selectivity : Expect to select 0.0004% of rows from table
> > > Expected row count: 37 rows after the scan
> > > Operation cost : 117
> > >
> > > Total cost : 117
> > > >>
> > How often do you update statistics? Are the results changing before and after statistics are updated? What is the primary key on the table? Are there statistics on the primary key as well as the index?
> I assume that when you wrote "TABLEID has 2 primary key, ID and CUSTOMER", you meant that the primary key contains two columns named ID and CUSTOMER.. Is that correct? A table cannot have two primary keys., so I don't know what else you could have meant.
>
> Are the two runs actually accessing the same table? Or is the DEFINE =TABLEID pointing to different tables for the two runs?
>
> Can you tell whether the number of rows accessed from the base table actually are approximately the numbers estimated by the EXPLAIN output (about 335 in one case and about 37 in the other)?
>
> Even if the number of rows accessed is about 335 vs. about 37, I would not expect either program to take enough time to run that you would feel the need to say that one of the runs is slow, unless the program performs an awful lot of work on each row that it accesses. What is the actual run time of the program in the two cases?
>
> I imagine that the value of ID that the two queries are selecting is different in the two jobs, and so it is correct that the number of rows that match the queries are different. Is that true, or are you getting a different number of rows actually selected when you run the same query twice?
>
> I never needed to use EXPLAIN plans very much, so I don't remember very much about interpreting them. But I have a feeling that these plans say that it is using the alternate index on ID rather than the initial part of the primary key (ID, CUSTOMER) in the scan. If the primary key actually is on (CUSTOMER, ID), then that would make sense, since the rows of the base table would not be grouped by ID. That would mean it would scan the index on ID, and for each row of the index that matched the value of ID, it would have to do a random read of the base table, jumping all around the base table rather than being able to sequentially read a subset of rows that are all together from the base table. That random access will make the program run slower than if the base table had ID as the most significant part of the primary key, but even so, it would still only be around 300 random reads from the base table, and that would not take very much longer than 30 or 40 random reads of the base table.
>
> If I had to make a guess based on the incomplete information given here, I would guess that the job that runs enough slower to warrant raising this question is actually accessing a lot more than 300 rows from the base table and has to access them randomly because the primary key does not have ID as its most significant column. The job that runs faster is still doing the random reads, but is accessing a much smaller number of rows. That guess might be wrong, so keep in mind that it is only my guess.
>
> That does not answer the question of why SQL computes a significantly different cost for the query in the two jobs. If my guess that the two jobs are not accessing the same table is not the answer for that part of puzzle, then I'd have to agree with Randall that the difference could have something to do with the statistics on the table, but I don't know enough about the optimizer to guess what is most likely to have gone wrong with the statistics.
>
> If the primary key of the table actually is (ID, CUSTOMER), then I think the plan should not be using the alternate index at all, and the reason it is using the alternate index would need to be addressed. Maybe something gone wrong with the statistics could have caused that, but I don't know enough to say what it could be.

My supposition is that the optimizer is picking the alternate index because the keys are fitting into a convenient set of blocks and would be faster to process than reading by primary key. That's partly where unspecified statistics can both mess up plans and provide misleading and inaccurate costs. The only true measure of performance is actually running the query with MEASURE monitoring the I/Os and SQL operations.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor