[Groonga-commit] pgroonga/pgroonga at 9376662 [master] Use index scan for many cases

Back to archive index

Kouhei Sutou null+****@clear*****
Sun May 24 00:09:16 JST 2015


Kouhei Sutou	2015-05-24 00:09:16 +0900 (Sun, 24 May 2015)

  New Revision: 9376662010826acc276e582bd9dacb7a9eea4b1b
  https://github.com/pgroonga/pgroonga/commit/9376662010826acc276e582bd9dacb7a9eea4b1b

  Message:
    Use index scan for many cases
    
    Because index scan is faster for many cases because bitmap scan requires
    bitmap heap scan. Bitmap heap scan is slow for large result set.
    
    This change is too naive. It should be improved.

  Modified files:
    pgroonga.c

  Modified: pgroonga.c (+25 -4)
===================================================================
--- pgroonga.c    2015-05-23 22:53:43 +0900 (716eaa8)
+++ pgroonga.c    2015-05-24 00:09:16 +0900 (3bcce9b)
@@ -14,6 +14,7 @@
 #include <lib/ilist.h>
 #include <mb/pg_wchar.h>
 #include <miscadmin.h>
+#include <optimizer/cost.h>
 #include <storage/bufmgr.h>
 #include <storage/ipc.h>
 #include <storage/lmgr.h>
@@ -2552,11 +2553,31 @@ pgroonga_vacuumcleanup(PG_FUNCTION_ARGS)
 Datum
 pgroonga_costestimate(PG_FUNCTION_ARGS)
 {
-	/*
-	 * We cannot use genericcostestimate because it is a static funciton.
-	 * Use gistcostestimate instead, which just calls genericcostestimate.
+	PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
+	IndexPath *path = (IndexPath *) PG_GETARG_POINTER(1);
+	double loopCount = PG_GETARG_FLOAT8(2);
+	Cost *indexStartupCost = (Cost *) PG_GETARG_POINTER(3);
+	Cost *indexTotalCost = (Cost *) PG_GETARG_POINTER(4);
+	Selectivity *indexSelectivity = (Selectivity *) PG_GETARG_POINTER(5);
+	double *indexCorrelation = (double *) PG_GETARG_POINTER(6);
+	IndexOptInfo *index = path->indexinfo;
+
+	/* TODO: Use more clever logic.
+	 * We want to use index scan instead of bitmap scan for full text search.
+	 * We want to use the default scan for other operators such as <,
+	 * <= and so on.
 	 */
-	return gistcostestimate(fcinfo);
+	*indexSelectivity = clauselist_selectivity(root,
+											   path->indexquals,
+											   index->rel->relid,
+											   JOIN_INNER,
+											   NULL);
+
+	*indexStartupCost = 0.0;
+	*indexTotalCost = 0.0;
+	*indexCorrelation = 0.0;
+
+	PG_RETURN_VOID();
 }
 
 /**
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index