Consolidating PK field types

Consolidating PK field types

by Martín Langhoff -
Number of replies: 25
In 1.9, we are moving PKs using bigint unsigned for the PKs. That is great, but we have to clear a few hurdles

* On an existing install we need to move all the fields that are PKs and the FKs that point to PKs to match in a single format. Otherwise, bad karma and slow performance will hit, as DBs cannot optimise JOINs where they have to do a CAST, even across int/bigint.
* Apparently some DBs cannot change the format of PKs easily. At least MySQL and Pg can wink we'll need a plan for the others.
* According to Petr, this is affecting sesskey issues, but I'm unsure how...

For the two first problems, I think we can write a post-install fixup script in commandline Perl or PHP. One that walks the PKs and FKs and fixes them all up.

For DBs that cannot do this "online", it'll take a dump, schema fixup, restore cycle that we can do with Perl/PHP. It's awful, but users of such DBs are used to it and -- dare I say -- consider their suffering a privilege wink
Average of ratings: -
In reply to Martín Langhoff

Re: Consolidating PK field types

by Mike Churchward -
Picture of Core developers Picture of Plugin developers Picture of Testers
If I understand what you are saying, this will affect any upgrade to 1.9, yes?

If so, I don't think we want to use any solution that cannot be done from a standard Moodle admin function, if we can at all help it. I really think we can't assume commandline Perl, as this is not a requirement for the installation of Moodle (is it?).

And, a schema dump fix up, if it requires manual interaction with the db would pretty much do a lot of Moodle users in. Sure there are a lot of users who enjoy this tech hacking, but there are a whole lot who cringe at the thought of it. I think we really need to come up with something that runs automatically, or at least from an admin command option (like the UTF8 conversion).

mike
In reply to Mike Churchward

Re: Consolidating PK field types

by Martín Langhoff -
Hi Mike,

anyone who is using Oracle/MSSQL (Eloy must have been thinking of Oracle at least) is used to cumbersome upgrades. And they are pretty upset that an app will try and edit its own schema -- it's The Job Of A Big And Expensive DBA... who can surely run a Perl script wink
In reply to Martín Langhoff

Re: Consolidating PK field types

by Mike Churchward -
Picture of Core developers Picture of Plugin developers Picture of Testers
Oh, no doubt... (but of course Moodle edits its own schema all the time...) wink

So, will this only affect the Oracle installations? Because if its needed by all installations, it will be an issue.

MSSQL might be an issue, as I don't think MS has perl by default...

mike

In reply to Martín Langhoff

Re: Consolidating PK field types

by Martín Langhoff -
The main problem is that if you _upgrade_ to 1.9 you will get a mix of ints (in old tables) and bigints (in new tables). When you do a JOIN between new and old tables using the mismatched PKs, the DB engine needs to CAST ints to bigints, and that kills performance. Big time.

On a fairly large DB we have at Catalyst (not Moodle related) some SELECTS that take about 1hr would instead take a few days if you mismatched your PKs. And the regression test suite would go from taking 1 day to complete to perhaps a week...?

So no - I don't want that to hit our production Moodle installs wink
In reply to Martín Langhoff

Re: Consolidating PK field types

by Eloy Lafuente (stronk7) -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Hi,

literally (Martin Langhoff suggested me to use this expression directly): tongueout

"wtf are you saying martin?"

Seriously,

starting with Moodle 1.7 (and with the XMLDB stuff to allow Moodle to work with - and sometimes, against, more RDBMS) all the table->id fields were re-defined as "BIGINT".

This was decided because the old "INT" definition wasn't enough to store really 10-digit numbers, see XMLDB column types article.

This means that all the tables created since Moodle 1.7 have these fields as BIGINTs , with their primary keys and so on, no problem.

So, only OLD sites (only running MySQL or PostgreSQL) can have a mix of "id" fields being INTs (old tables) and BIGINTs (new tables).

And all those sites have been working that way since Moodle 1.7. And nothing is going to change in that area for Moodle 1.9. With the new release will be some new tables, all them created with BIGINTs (like in 1.7 and 1.8). That's all.

I agree that theoretically comparing INTs with BIGINTs in queries can cause one small performance penalty but nothing like having to perform heavy casts nor invalidating indexes.

The only point that is going to change in Moodle 1.9, related to those id fields is that, some hours ago, Petr has detected that, due to one bug in the XMLDB editor, those tables created after Moodle 1.7 have their "id" field declared as signed and we are going to change them to unsigned. We have been testing the script some hours ago and seems to work perfectly under MySQL (the only one DB affected, because all the rest haven't that "signed/unsigned" differentiation in their declaration).

So, or I'm forgetting something (it's perfectly possible) or the upgrade to Moodle 1.9 doesn't show any problem at all, no primary keys will be lost nor anything similar.

So, yes, old sites have one mix of INTs and BIGINTs in their primary keys, agree, since Moodle 1.7. But nothing is going to change for 1.9.

Perhaps we could try to add one script to "normalise" that situation as part of the upgrade script but sincerely I think it isn't critic and could be implemented for 2.0.

Ciao smile
In reply to Eloy Lafuente (stronk7)

Re: Consolidating PK field types

by Martín Langhoff -

Hi Eloy.

So this is in place. Ok, then I saw it and thought it was a newish 1.9-ish thing. I am a very slow boy!

However, this is a pretty serious performance problem. It's not theoretical -- it means indexes are ignored and that a JOIN that was pretty much bitmapped (read: superfast) now forces a CAST. Pg and MySQL both hurt badly on this.

If you have a large DB around, try an EXPLAIN of a SELECT that joins user_preferences to user, before and after changing user.id. You will see that the plan is completely different.

In reply to Martín Langhoff

Re: Consolidating PK field types

by Eloy Lafuente (stronk7) -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Hi Martin,

agree about that there is a penalty... but really not sure if it's serious. I remember myself creating 2 big tables (oldtable and newtable), each one with one different INT type... and joining them caused a small penalty because some sort was performed in the middle of two sequential index scans.

And the difference, in terms of cost, weren't really high (specially if the query was returning small recordsets).

But yes, perhaps we could normalize the situation before 2.0. It shouldn't be really difficult to do that for MySQL (not 100% sure about PostgreSQL 7.4 and their alter table possibilities and sequences).

Any idea?

Ciao smile

Edited: Reviewing my notes... I think that there was some limitation under PostgreSQL 7.4... not allowing to change the type of a field directly... so all those fields must be duplicated, dropped and PKs and sequences recreated... (really hard) while PG 8.x allowed direct and simple change of the type from int4 to int8... does this sound to you?
In reply to Eloy Lafuente (stronk7)

Re: Consolidating PK field types

by Martín Langhoff -

I think it's worth fixing. The difference is low in numbers, but high in percentage. So at the end of the day, and over thousand of DB queries, it is huge.

In my trivial example below, the difference is more than double (from 3502.21..13503.20 to 7010.62..34427.98 estimated cost). See the query plan with and without a forced cast:

op_18moodle=> explain select u.username from mdl_user u join mdl_user_preferences p on p.userid=u.id;
                                     QUERY PLAN                                     
------------------------------------------------------------------------------------
 Hash Join  (cost=3502.21..13503.20 rows=250333 width=15)
   Hash Cond: (p.userid = u.id)
   ->  Seq Scan on mdl_user_preferences p  (cost=0.00..4994.33 rows=250333 width=4)
   ->  Hash  (cost=2837.65..2837.65 rows=53165 width=19)
         ->  Seq Scan on mdl_user u  (cost=0.00..2837.65 rows=53165 width=19)
(5 rows)

op_18moodle=> explain select u.username from mdl_user u join mdl_user_preferences p on p.userid=u.id::bigint ;
                                                               QUERY PLAN                                                            
---------------------------------------------------------------------------------------------------------------------------------
 Merge Join  (cost=7010.62..34427.98 rows=490472 width=15)
   Merge Cond: (p.userid = "inner"."?column3?")
   ->  Index Scan using mdl_user_preferences_useridname_idx on mdl_user_preferences p  (cost=0.00..17582.44 rows=250333 width=4)
   ->  Sort  (cost=7010.62..7143.53 rows=53165 width=19)
         Sort Key: (u.id)::bigint
         ->  Seq Scan on mdl_user u  (cost=0.00..2837.65 rows=53165 width=19)
(6 rows)

And actually running them with explain analyse shows it bears out

 No cast
 Total runtime: 1134.926 ms

 Cast to bigint
 Total runtime: 2457.717 ms

So there you go - bring a big axe, and chop your DB load in half.

In reply to Eloy Lafuente (stronk7)

Re: Consolidating PK field types

by Martín Langhoff -

perhaps we could normalize the situation before 2.0.

Great idea! smile

I think it needs to be an optional script, commandline (I'd do it in perl, but the natural thing is to do it in PHP), full of "backup your DB" warnings that bipasses complexities of dancing with XMLDB and friends and does whatever needs to be done for each DB.

Small self-hosted moodles might not see or care about the impact or want to deal with the complexities of this. But we need it in the arsenal for larger DBs.

In reply to Martín Langhoff

Re: Consolidating PK field types

by Eloy Lafuente (stronk7) -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Some thoughts:

A) About your example above:

1) IMO, the "double time" conclusion above is inaccurate. Both when the fields are the same type or when they are different, the table is accessed by his primary key. Same speed. The only difference is that the merge is being done by hash when they are the same type and by sort when different types are used. And comparing "sort" vs "hash"... as I said above, differences are really minimal when normal (up to, say,100 records) recordsets are fetched from DB.

2) Also, the explicit CAST performed in your query... uhm... I've serious doubts about it being a good representation of the current situation. The explain plan shows the explicit CAST as part of the process, and I'm 99% sure that, when I tested and compared how joins performed (with REAL tables having different types), that explicit CAST didn't happen, causing more similar times to be achieved.

3) So, say, one 10% of throughput is lost when fields are different, but not one 100%, IMO.

B) About Foreign Keys

1) Yes, they are pretty cool. Some day we'll have to implement them, although I'm sure you know their costs (in terms or speed, cross-db and so on). In fact, the XMLDB stuff is, more or less, ready to support them (on DDL statements). Of course, they are the correct way in a strong relational world, absolutely!

2) Right now (from Moodle 1.7 and upwards) practically ALL those logic FKs have the correct index created, so currently, JOINs are flying now. I don't expect any improvement once physical FK will be implemented.

C) About the homogenization of types

1) It only affects MySQL and PostgreSQL (only databases installed before 1.7 can have this mix of types). So both MSSQL and Oracle are correct BIGINTs since the beginning.

2) Is it a crazy idea to raise min requeriments for PostgreSQL to 8.0 ? This way, the script to be executed is really easy to be created and can be added officially to the XMLDB editor to provide automatically the necessary statements to be executed (like the "missing indexes" search and create option). I really prefer that way to perform the change automatically as part of the upgrade process (too much changes!).

Ciao smile
In reply to Eloy Lafuente (stronk7)

Re: Consolidating PK field types

by Martín Langhoff -

Hi Eloy!

differences are really minimal when normal (up to, say,100 records)

The thing is -- normal recordset are no longer 100 records mixed . Modern moodle (v1.7 onwards) is not about tables with 100 records.

Quiz tables get huge. Events tables get huge. user_prefernces and user_info. log. Backup's own backupids table. Forum discussions and posts. Scorm scoeds. And don't forget the new grades stuff.

Even mdl_config on a new install has more than 100.

So, say, one 10%

Why should we opine if we can test? smile

Show me a DB query over a large dataset that with/without an implicit cast has 10% difference.

only databases installed before 1.7 can have this mix of types

Sure. But a zillion installs out there started with us with 1.3/1.4. And most of the large scale setups I'm aware of are on 1.4/1.5/1.6.

Is it a crazy idea to raise min requeriments for PostgreSQL to 8.0

Not at all. I'm all for it. v7.4 is slow and problematic. The Pg v8.x series is rock solid, and widerly deployed...

I really prefer that way to perform the change automatically as part of the upgrade process (too much changes!).

Agreed!

In reply to Martín Langhoff

Re: Consolidating PK field types

by Eloy Lafuente (stronk7) -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Arghh,

I'm not talking about tables with 100 records. I'm talking about returned recordsets with more than 100 records (with 100 being just an example meaning "not thousands of records").

The only difference between having those fields matched or no is how both tables are merged and the merge "cost" is really dependent of the number of records retrieved from each table.

So, your example above, returning al FULL (without "extra" conditions) INNER join isn't real because of, at least, two causes:

1) It has one explicit cast. It doesn't happen in real live. So, it's cost doesn't happen, so times above are exaggerated (comparing them with real life).

2) It's returning ALL records in the join (50.000 at least). Under that numbers the merge between tables is really better when it's performed by HASH than by SORT. But I guess there aren't too many queries in Moodle returning those numbers. Queries use to be more "concrete" having extra conditions like "AND userid = XXX" and so on, that, dramatically make merge costs similar (that's what I tested with some thousands of records).

Anyway, as I know that two latin guys can be talking about this for ages, big grin... what if, to fix this extra (10% -- 100%) SQL cost we:

1) Raise Moodle 1.9 min PG version to 8.0 (is 8.1 a better choice ?).

2) Add one utility (implemented over the XMLDB editor), to search and provide one list of SQL statements to be executed, leaving the process out from the upgrade, like the "Missing indexes" utilitiy is right now. I guess that the process will iterate over all the tables and columns in DB and, each time one "small" int is found (and its XML definition is integer(10), will change it to bigint (int8). Just that.

Ciao smile

Edited: And only for MySQL and Pg wink
In reply to Eloy Lafuente (stronk7)

Re: Consolidating PK field types

by Martín Langhoff -

I think that there was some limitation under PostgreSQL 7.4

IIRC you are right. No prob - PKs are not magic in Pg, we can add new col, copy data, drop old col, rename newcol to id, recreate sequences & indexes. Nothing that a for loop and some SQL cannot resolve wink

I think might be the same in Oracle.

In reply to Martín Langhoff

Re: Consolidating PK field types

by Penny Leach -
One of those reasons we're lucky we're not using proper foreign key constraints - it becomes a lot harder when you have actual real FKs.

Disclaimer: I wish we did have real FKs wink
In reply to Penny Leach

Re: Consolidating PK field types

by Martín Langhoff -
I also wish we had real FKs smile - then we could make indexes on FK mappings so that the JOINs fly.

yummy.

And a pony, too! Want wanttttt!
In reply to Martín Langhoff

Re: Consolidating PK field types

by Eloy Lafuente (stronk7) -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Things are changing... quickly: cool

1- Since some hours ago, Moodle 1.9 will require at least PostgreSQL 8.0.

2- Since some minutes ago, in CVS (HEAD only), there is one new utility built in the XMLDB editor. It's called "Check Bigints" and you can find it in the XMLDB Editor main page.

That utility will iterate over all the tables and fields in the install.xml files, comparing them with the physical database where Moodle is running. At the end, it will inform of changes that aren't correct BIGINTs, providing the SQL to execute in order to fix the problem.

Note that the utility itself DOESN'T perform any modification of the database, so it's 100% safe to execute it when desired. Instead, it provides you with the SQL to execute in you favorite SQL interface. Obviously, it's highly recommended to backup everything before executing such SQLs.

I've performed some tests here and everything seems to work (with underlying sequences, indexes or keys being respected in the change).

Note that this utility is only available for MySQL and PostgreSQL databases (because the problem, simply, doesn't exist in other DB flavours).

It would be great to have some feedback of the execution of the utility (and the proposed SQLs) in your test servers. Absolutely!

And, once more, don't forget to backup your DB before executing those SQLs, specially in a production server!

TIA and ciao smile

P.S. For your info, the related bug for all this is MDL-11038
In reply to Eloy Lafuente (stronk7)

Re: Consolidating PK field types

by Martín Langhoff -

Running it now on my 1.8. Looks good...

one minor thing though: it wants to convert any int to bigint, including ints we use for timestamps and for booleans. I don't mind it per se, but the storage and index costs do double up.

For others playing with this...

  • executing the changes it proposes can nail your DB server for hours if you have a large system
  • the on-disk size of your DB will grow quite a bit, make sure there is space

BTW, I've found a very big optimisation we can do on Pg indexes. Is there a way to pass "magic flags" to the XMLDB index creator? I want to say

CREATE INDEX foo 
ON mdl_context (path varchar_pattern_ops)

without that, WHERE path LIKE '/foo%' is not optimised in Postgres when using UTF-8. More notest in http://www.postgresql.org/docs/8.1/static/indexes-opclass.html

In reply to Martín Langhoff

Re: Consolidating PK field types

by Eloy Lafuente (stronk7) -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Hi Martín,

AFAIK it doesn't want to convert ANY int to bigint. It only converts integer(10) that are incorrectly defined in DB (i.e. like simple "int" under mysql or "int4" under pg, let's call them "smaller-ints"), making them bigints. That's the expected behaviour because those "smaller-ints" aren't enough to store the maximum integer(10) value.

Isn't it working that way?

Of course, size will grown, of course (as a quick measure... 100 millions of changes will produce one increment of 380MB). I hope people having to perform 100 millions of changes won't have problems to add, say 10GB to their disks). That should cover indexes and anything else wink

Finally, no. There isn't any option to pass special flags to DDL statements. sad
(and I'm not sure if it's a good idea - at least until a good plan will be available about how to keep all those "special flags" support running well. It's against the basis of the XMLDB stuff, in my initial, and personal opinion).

Also, I don't know if it's important or no but, as far as I know, LIKE statements (not ILIKE ones), using righted wildcards should work perfectly, no matter of the LOCALE being used. I've some notes about that, when I was comparing some DBs for the XMLDB transition and, literally, they say (in my slang):

- "right wilcards use indexes on all DBs (NOTE: but not with ILIKE nor left wilcards)

Hope this helps, if your queries are going to be "right wildcards".

Ciao smile
In reply to Eloy Lafuente (stronk7)

Re: Consolidating PK field types

by Martín Langhoff -

Maybe I saw a few ints that I didn't expect to see. But you are right -- things that are clearly smallints (visible, etc) weren't converted. I do think we have a few ints that could be smallints. Small fry really.

And yeah, the SQL it proposed killed my laptop for about 2hs. Ha ha ha. And the DB grew a lot - I didn't measure it, but wanted to warn people smile

Finally, no. There isn't any option to pass special flags to DDL statements.

I thought so. And I agree it's a bad idea. However, my favourite DB needs one for performance.

as far as I know, LIKE statements (not ILIKE ones), using righted wildcards should work perfectly, no matter of the LOCALE being used

I was saying the same until 24hs ago - but I have just learned that it's not true. Did an EXPLAIN on a query and found it was scanning the field. A bit of googling found this

"The optimizer can also use a B-tree index for queries involving the pattern matching operators LIKE and ~ if the pattern is a constant and is anchored to the beginning of the string — for example, col LIKE 'foo%' or col ~ '^foo', but not col LIKE '%bar'. However, if your server does not use the C locale you will need to create the index with a special operator class to support indexing of pattern-matching queries."

http://www.postgresql.org/docs/8.1/static/indexes-types.html

And when I recreated the index with the varchar_pattern_ops "magic option" the problem was fixed.

I do wonder why Pg doesn't do it by default? There may be an additional cost to maintaining it?

In reply to Martín Langhoff

Re: Consolidating PK field types

by Eloy Lafuente (stronk7) -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Uhm....

I'm pretty sure that the LIKE 'foo%' should be a special case, not needing anything like pattern_ops and similar. I agree that both left wildchars, ilike conditions and regular expressions will need that under other locales, but the LIKE 'foo%' too?

I said that because LIKE 'foo%' is pretty equivalent to:

field >= 'foo' AND field < 'fop' and I think that's the way PG uses to perform that queries, using the index, of course.

I read that somewhere, long time ago. Just don't remember where. Just trying to see if with this special (and common) case you don't need those special (and non-cross-db) artifacts. wink

Ciao smile

Edited: Just made a quick test and got this:

moodle_head=# explain select * from test where content like 'xxx%';
QUERY PLAN
------------------------------------------------------------------------------------------------------------
Index Scan using test_ix on test (cost=0.00..9.30 rows=2 width=222)
Index Cond: (((content)::text >= 'xxx'::character varying) AND ((content)::text < 'xxy'::character varying))
Filter: ((content)::text ~~ 'xxx%'::text)

Doesn't that mean that the query is resolved by using the index? In a similar fashion than the one I remembered ? (I must confess that I'm not an specialist in PostgreSQL plans so...).

Re-ciao smile
In reply to Eloy Lafuente (stronk7)

Re: Consolidating PK field types

by Martín Langhoff -

Eloy, I completely agree with you, but I think it depends a lot on the DB creation locale. What is the locale on your setup? Mine is

 $ locale
 LANG=en_US.UTF-8
 LC_CTYPE="en_US.UTF-8"
 LC_NUMERIC="en_US.UTF-8"
 LC_TIME="en_US.UTF-8"
 LC_COLLATE="en_US.UTF-8"
 LC_MONETARY="en_US.UTF-8"
 LC_MESSAGES="en_US.UTF-8"
 LC_PAPER="en_US.UTF-8"
 LC_NAME="en_US.UTF-8"
 LC_ADDRESS="en_US.UTF-8"
 LC_TELEPHONE="en_US.UTF-8"
 LC_MEASUREMENT="en_US.UTF-8"
 LC_IDENTIFICATION="en_US.UTF-8"
 LC_ALL=

So on my Pg8.2 -- and according to the doco this is since 7.2 -- I get a bad sequential scan because the locale isn't "C":

EXPLAIN SELECT * from mdl_context WHERE path LIKE '/1/14/15/%';
                      QUERY PLAN                           
---------------------------------------------------------------
 Seq Scan on mdl_context  (cost=0.00..1132.53 rows=1 width=40)
   Filter: ((path)::text ~~ '/1/14/15/%'::text)

But if I create an index with the required magic, we are back to the good plans...

CREATE INDEX foo ON mdl_context(path varchar_pattern_ops);
EXPLAIN SELECT * from mdl_context WHERE path LIKE '/1/14/15/%';
                                                        QUERY PLAN                                                        
--------------------------------------------------------------------------------------------------------------------------
 Index Scan using foo on mdl_context  (cost=0.00..8.28 rows=1 width=40)
   Index Cond: (((path)::text ~>=~ '/1/14/15/'::character varying) AND ((path)::text ~<~ '/1/14/150'::character varying))
   Filter: ((path)::text ~~ '/1/14/15/%'::text)

Don't know if there's a way to control the locale when we connect to Pg (to set it to C). Even then, using the "C" locale is a pretty bad move for non-English sites - means collations and other bits and pieces will be wrong.

Not sure what the answer is here, really. mixed

Edit: Trying to understand exactly what variable it is that is affecting me. I think it is LC_CTYPE, which you can see if you say SHOW ALL or SHOW lc_ctype (en_US.UTF-8). OTOH, I created this DB saying createdb -E utf-8 ; now that is just the encoding but perhaps it's locked me down to a utf-8 locale?

Ah, grumble - yes it has. You cannot SET lc_ctype. sad

In reply to Martín Langhoff

Re: Consolidating PK field types

by Eloy Lafuente (stronk7) -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Mine is:

$ locale
LANG="es_ES.UTF-8"
LC_COLLATE="es_ES.UTF-8"
LC_CTYPE="es_ES.UTF-8"
LC_MESSAGES="es_ES.UTF-8"
LC_MONETARY="es_ES.UTF-8"
LC_NUMERIC="es_ES.UTF-8"
LC_TIME="es_ES.UTF-8"
LC_ALL="es_ES.UTF-8"

and DB was created with "encoding 'utf-8'", for sure.

Also, one quick note about the "varchar_pattern_ops" and gang. It seems that both indexes (the normal and the pattern_ops) one can be created at the same time. In fact, I guess than BOTH will be necessary depending of the query performed. One is optimal for pattern-matching but the other can be necessary for ORDERs and equalities.

Anyway... are you saying, after reading your post above, that if you unset the LC_CTYPE env variable and then execute the query, the index is used or that it depends of the moment of creation of the DB? (just for clarification).

Ciao smile
In reply to Eloy Lafuente (stronk7)

Re: Consolidating PK field types

by Martín Langhoff -

I think that the LC_CTYPE is read from your env at postgres instance setup -- and gets set in stone for that instance. You can not even change it per-database, and you cannot change it per-connection. In Pg documentation it talks about lc_ctype beeing set at dbinit which is the script that runs during installation.

If you ask Pg what the LC_CTYPE is, with SHOW ALL, what does it say? (My guess is that it will say "C").

If your Pg has a non-C LC_CTYPE then I don't know WTF is going on here...

In terms of having both indexes - I have been thinking about that yesterday. I think that the _pattern_ops will probably also resolve equality, but not ORDERs and stuff like that. In any case, for context.path we only use LIKE "?????%' on it. In any case, the documentation isn't being very helpful - the only way to know is to test it wink

In reply to Martín Langhoff

Re: Consolidating PK field types

by Eloy Lafuente (stronk7) -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Ah!!

mine is C C C C C C C C (only one! wink ). So, that's the cause I was viewing indexes working in my tests!

Sorry by the delay. Ciao smile
In reply to Eloy Lafuente (stronk7)

Re: Consolidating PK field types

by Martín Langhoff -

Hah. I knew it! wide eyes

Anyway, there's a bit of discussion at pgsql-general about this, and was talking with Eloy about what to do with these funky indexen. If the pg hackers insist that there isn't a runtime workaround, Eloy proposes a soft "hint" in the XMLDB reports page. I like the idea.

http://archives.postgresql.org/pgsql-general/2007-09/msg00121.php

(And if later turns out that we have lots of special index things for different DBs, this may become a series of extensions to xmldb. For now... keep it simple.)