Subject: Re: maybe a bug

From: Jan Wielemaker <[email-masked]>
Date: Fri, 18 Jan 2002 11:07:47 +0100

[ 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