From jan@swi.psy.uva.nl Fri Jan 18 11:07:47 2002
Received: from there (jan@gollem.swi.psy.uva.nl [145.18.152.30])
	by swi.psy.uva.nl (8.11.6/8.11.2) with SMTP id g0IA7lT17707;
	Fri, 18 Jan 2002 11:07:47 +0100 (MET)
Message-Id: <200201181007.g0IA7lT17707@swi.psy.uva.nl>
Content-Type: text/plain;
  charset="iso-8859-1"
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Organization: SWI, University of Amsterdam
To: "Tolga Konik" <konik@umich.edu>
Subject: Re: maybe a bug
Date: Fri, 18 Jan 2002 11:07:47 +0100
X-Mailer: KMail [version 1.3.2]
References: <001601c19f88$e0802e30$fe12d58d@eecs.umich.edu>
In-Reply-To: <001601c19f88$e0802e30$fe12d58d@eecs.umich.edu>
Cc: prolog
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

[ copied to the mailing list.  Please keep things of general interest there,
  so people can search the archive for answers
]

On Thursday 17 January 2002 19:57, you wrote:
> Hi,
>
> I have noticed that a query foo(_,_X) works faster on the default index
> foo(1,0,0) than on the index foo(0,0,1). (it works fastest for foo(1,0,1)).
>
> If this is not expected behaviour, let me know, I will try to extract more
> details.

This is intended behaviour.  SWI-Prolog clause indexing has various
algorithms.  Normally, each clause is associated with a key and a mask.
After calculating the key for the actual goal the clause-list is traversed
looking for a candidate.  99% of the clauses being indexed on the first
argument only, the system starts to check for this and uses dedicated and
faster code than the general multi-argument indexing which is used for
predicates indexed on another than the first argument.

In addition, if there are enough clauses with indexable first argument the
system starts maintaining a hash-table.  It only does this for predicates
indexed on the first argument only.

	Cheers --- Jan



