pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Simple PHP/pgsql optimization question...
3+ messages / 3 participants
[nested] [flat]

* Simple PHP/pgsql optimization question...
@ 2002-05-18 15:14  Gaëtan de Menten <ged@bugfactory.org>
  0 siblings, 2 replies; 3+ messages in thread

From: Gaëtan de Menten @ 2002-05-18 15:14 UTC (permalink / raw)
  To: pgsql-php

Hi there all,

First, I'm far from being a professional programmer in pgsql and PHP and I'm
new to this list, so please pardon if this question seems stupid to you.

In my 'projects' tables, among many other fields, I need a 'license' field.
I need to optimize the display of the list of all projects (+-200 projects
to display).
Which solution do you think would be the fastest, and how much faster?

1) Have a 'license' table (with and id and a name field) listing all the
possible licenses and have a foreign key in my 'projects' table pointing to
that 'license' table.
the query would look like this:
select ..., license.name as license from projects, licenses where
projects.license=license.id and ...

2) Have the license field in the 'projects' table be a varchar field and
store the name of the license directly.

3) Have the license field be an int and have an array in PHP listing all the
licenses.

4) another solution?

I personnaly prefer the first solution since it's the cleanest to my eyes
but I'm ready to trade that for speed, if another solution is much faster.

Thanks a lot,
Gaëtan.




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Simple PHP/pgsql optimization question...
@ 2002-05-18 15:47  Chadwick Rolfs <cmr@shell.gis.net>
  parent: Gaëtan de Menten <ged@bugfactory.org>
  1 sibling, 0 replies; 3+ messages in thread

From: Chadwick Rolfs @ 2002-05-18 15:47 UTC (permalink / raw)
  To: Gaëtan de Menten <ged@bugfactory.org>; +Cc: pgsql-php

On Sat, 18 May 2002, [iso-8859-1] Gaëtan de Menten wrote:

> Hi there all,
> 
> First, I'm far from being a professional programmer in pgsql and PHP and I'm
> new to this list, so please pardon if this question seems stupid to you.
> 
> In my 'projects' tables, among many other fields, I need a 'license' field.
> I need to optimize the display of the list of all projects (+-200 projects
> to display).
> Which solution do you think would be the fastest, and how much faster?
> 
> 1) Have a 'license' table (with and id and a name field) listing all the
> possible licenses and have a foreign key in my 'projects' table pointing to
> that 'license' table.
> the query would look like this:
> select ..., license.name as license from projects, licenses where
> projects.license=license.id and ...
> 
> 2) Have the license field in the 'projects' table be a varchar field and
> store the name of the license directly.
> 
> 3) Have the license field be an int and have an array in PHP listing all the
> licenses.
> 
> 4) another solution?
> 
> I personnaly prefer the first solution since it's the cleanest to my eyes
> but I'm ready to trade that for speed, if another solution is much faster.
> 
> Thanks a lot,
> Gaëtan.

I prefer the first solution also.  You can add or take away liscenses
without having to edit a huge amount of data.  Be sure you do the right
thing with the foreign key.  I would leave most of the data handling to
postgresql and use php to make it accessable(sp?) in a
pretty way....

-Chadwick




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Simple PHP/pgsql optimization question...
@ 2002-05-18 18:10  Keary Suska <hierophant@pcisys.net>
  parent: Gaëtan de Menten <ged@bugfactory.org>
  1 sibling, 0 replies; 3+ messages in thread

From: Keary Suska @ 2002-05-18 18:10 UTC (permalink / raw)
  To: pgsql-php

on 5/18/02 9:14 AM, ged@bugfactory.org purportedly said:

> In my 'projects' tables, among many other fields, I need a 'license' field.
> I need to optimize the display of the list of all projects (+-200 projects
> to display).
> Which solution do you think would be the fastest, and how much faster?
> 
> 1) Have a 'license' table (with and id and a name field) listing all the
> possible licenses and have a foreign key in my 'projects' table pointing to
> that 'license' table.
> the query would look like this:
> select ..., license.name as license from projects, licenses where
> projects.license=license.id and ...
> 
> 2) Have the license field in the 'projects' table be a varchar field and
> store the name of the license directly.
> 
> 3) Have the license field be an int and have an array in PHP listing all the
> licenses.
> 
> 4) another solution?

The main issue is the relationship between licenses and projects. Can there
be more than one license per project, or multiple projects per license, or
both? Or is there only one license per project? Only in this last case is it
advisable to have the license field in the project table. Data integrity
should never be sacrificed for any reason, even speed. But if you are
talking about hundreds of records, you should not notice any speed
difference regardless of how you implement it, at least as far as Postgres
is concerned.

Your solution #1 works properly only if there are multiple projects per
license, and is the best solution in that case.

Keary Suska
Esoteritech, Inc.
"Leveraging Open Source for a better Internet"




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2002-05-18 18:10 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-05-18 15:14 Simple PHP/pgsql optimization question... Gaëtan de Menten <ged@bugfactory.org>
2002-05-18 15:47 ` Chadwick Rolfs <cmr@shell.gis.net>
2002-05-18 18:10 ` Keary Suska <hierophant@pcisys.net>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox