|
7 | 7 | *
|
8 | 8 | *
|
9 | 9 | * IDENTIFICATION
|
10 |
| - * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.17 1997/01/25 19:29:36 scrappy Exp $ |
| 10 | + * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.18 1997/01/29 02:59:03 vadim Exp $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
@@ -68,6 +68,7 @@ static void _vc_rpfheap (VRelList curvrl, Relation onerel, VPageList Vvpl, VPage
|
68 | 68 | static void _vc_vacheap (VRelList curvrl, Relation onerel, VPageList vpl);
|
69 | 69 | static void _vc_vacpage (Page page, VPageDescr vpd, Relation archrel);
|
70 | 70 | static void _vc_vaconeind (VPageList vpl, Relation indrel, int nhtups);
|
| 71 | +static void _vc_scanoneind (Relation indrel, int nhtups); |
71 | 72 | static void _vc_updstats(Oid relid, int npages, int ntuples, bool hasindex);
|
72 | 73 | static void _vc_setpagelock(Relation rel, BlockNumber blkno);
|
73 | 74 | static VPageDescr _vc_tidreapped (ItemPointer itemptr, VPageList curvrl);
|
@@ -400,34 +401,38 @@ _vc_vacone (VRelList curvrl)
|
400 | 401 | Vvpl.vpl_npages = Fvpl.vpl_npages = 0;
|
401 | 402 | _vc_scanheap(curvrl, onerel, &Vvpl, &Fvpl);
|
402 | 403 |
|
403 |
| - /* Now open/count indices */ |
| 404 | + /* Now open indices */ |
404 | 405 | Irel = (Relation *) NULL;
|
405 |
| - if ( Vvpl.vpl_npages > 0 ) |
406 |
| - /* Open all indices of this relation */ |
407 |
| - _vc_getindices(curvrl->vrl_relid, &nindices, &Irel); |
408 |
| - else |
409 |
| - /* Count indices only */ |
410 |
| - _vc_getindices(curvrl->vrl_relid, &nindices, NULL); |
| 406 | + _vc_getindices(curvrl->vrl_relid, &nindices, &Irel); |
411 | 407 |
|
412 | 408 | if ( nindices > 0 )
|
413 | 409 | curvrl->vrl_hasindex = true;
|
414 | 410 | else
|
415 | 411 | curvrl->vrl_hasindex = false;
|
416 | 412 |
|
417 |
| - /* Clean index' relation(s) */ |
| 413 | + /* Clean/scan index relation(s) */ |
418 | 414 | if ( Irel != (Relation*) NULL )
|
419 | 415 | {
|
420 |
| - for (i = 0; i < nindices; i++) |
421 |
| - _vc_vaconeind (&Vvpl, Irel[i], curvrl->vrl_ntups); |
| 416 | + if ( Vvpl.vpl_npages > 0 ) |
| 417 | + { |
| 418 | + for (i = 0; i < nindices; i++) |
| 419 | + _vc_vaconeind (&Vvpl, Irel[i], curvrl->vrl_ntups); |
| 420 | + } |
| 421 | + else /* just scan indices to update statistic */ |
| 422 | + { |
| 423 | + for (i = 0; i < nindices; i++) |
| 424 | + _vc_scanoneind (Irel[i], curvrl->vrl_ntups); |
| 425 | + } |
422 | 426 | }
|
423 | 427 |
|
424 | 428 | if ( Fvpl.vpl_npages > 0 ) /* Try to shrink heap */
|
425 | 429 | _vc_rpfheap (curvrl, onerel, &Vvpl, &Fvpl, nindices, Irel);
|
426 |
| - else if ( Vvpl.vpl_npages > 0 ) /* Clean pages from Vvpl list */ |
| 430 | + else |
427 | 431 | {
|
428 | 432 | if ( Irel != (Relation*) NULL )
|
429 | 433 | _vc_clsindices (nindices, Irel);
|
430 |
| - _vc_vacheap (curvrl, onerel, &Vvpl); |
| 434 | + if ( Vvpl.vpl_npages > 0 ) /* Clean pages from Vvpl list */ |
| 435 | + _vc_vacheap (curvrl, onerel, &Vvpl); |
431 | 436 | }
|
432 | 437 |
|
433 | 438 | /* ok - free Vvpl list of reapped pages */
|
@@ -1266,6 +1271,51 @@ _vc_vacpage (Page page, VPageDescr vpd, Relation archrel)
|
1266 | 1271 |
|
1267 | 1272 | } /* _vc_vacpage */
|
1268 | 1273 |
|
| 1274 | +/* |
| 1275 | + * _vc_scanoneind() -- scan one index relation to update statistic. |
| 1276 | + * |
| 1277 | + */ |
| 1278 | +static void |
| 1279 | +_vc_scanoneind (Relation indrel, int nhtups) |
| 1280 | +{ |
| 1281 | + RetrieveIndexResult res; |
| 1282 | + IndexScanDesc iscan; |
| 1283 | + int nitups; |
| 1284 | + int nipages; |
| 1285 | + struct rusage ru0, ru1; |
| 1286 | + |
| 1287 | + getrusage(RUSAGE_SELF, &ru0); |
| 1288 | + |
| 1289 | + /* walk through the entire index */ |
| 1290 | + iscan = index_beginscan(indrel, false, 0, (ScanKey) NULL); |
| 1291 | + nitups = 0; |
| 1292 | + |
| 1293 | + while ((res = index_getnext(iscan, ForwardScanDirection)) |
| 1294 | + != (RetrieveIndexResult) NULL) |
| 1295 | + { |
| 1296 | + nitups++; |
| 1297 | + pfree(res); |
| 1298 | + } |
| 1299 | + |
| 1300 | + index_endscan(iscan); |
| 1301 | + |
| 1302 | + /* now update statistics in pg_class */ |
| 1303 | + nipages = RelationGetNumberOfBlocks(indrel); |
| 1304 | + _vc_updstats(indrel->rd_id, nipages, nitups, false); |
| 1305 | + |
| 1306 | + getrusage(RUSAGE_SELF, &ru1); |
| 1307 | + |
| 1308 | + elog (MESSLEV, "Ind %.*s: Pages %u; Tuples %u. Elapsed %u/%u sec.", |
| 1309 | + NAMEDATALEN, indrel->rd_rel->relname.data, nipages, nitups, |
| 1310 | + ru1.ru_stime.tv_sec - ru0.ru_stime.tv_sec, |
| 1311 | + ru1.ru_utime.tv_sec - ru0.ru_utime.tv_sec); |
| 1312 | + |
| 1313 | + if ( nitups != nhtups ) |
| 1314 | + elog (NOTICE, "NUMBER OF INDEX' TUPLES (%u) IS NOT THE SAME AS HEAP' (%u)", |
| 1315 | + nitups, nhtups); |
| 1316 | + |
| 1317 | +} /* _vc_scanoneind */ |
| 1318 | + |
1269 | 1319 | /*
|
1270 | 1320 | * _vc_vaconeind() -- vacuum one index relation.
|
1271 | 1321 | *
|
|
0 commit comments