« first day (1290 days earlier)      last day (1368 days later) » 

12:21 AM
hello
I am trying to build a trigger in MySQL
 
 
3 hours later…
2:58 AM
hello
is good if a table have single index on a and b colum , and have other composite index on a and b column ?
 
 
13 hours later…
4:00 PM
@Eatlon how's that working out?
@reza_daulay you mean, an index on (a,b) and another index on (b,a)? Or an index on (a), an index on (b), and another index on (a,b)?
 
 
2 hours later…
5:51 PM
Hey! do you know if doing about 10 database calls when doing one search is too much?
or is it better to use UNION so I do only one big query? problem is number of columns on each query is not the same
 
@Ant100 against different tables?
@Ant100 it wouldn't make any difference for database expense. As long as you parallelize the queries, you should be good.
 
@TehShrike yes different tables
@TehShrike oh what do you mean parallelize?
 
@Ant100 make sure all the queries start running at the same time
don't wait until one is finished to start running the next
 
@TehShrike hmm.. I got a bunch of conditionals so if search fields from form are empty, it should not do that query and go on to the next. Will that make the querys wait?
 
@Ant100 yeah, but if that's what you've got to do, that's what you've got to do
though perhaps you could do it with a join?
 
6:09 PM
@TehShrike I am using join in a few of the queries, but I tried thinking a way of doing it with the entire thing and I believe my brain exploded a little. I'll just leave it like that. Thanks :) :)
or maybe I could do something like this: SELECT * FROM Table1, Table2, etc and do a DISTINCT at the end to avoid duplicates?
 
 
2 hours later…
7:50 PM
@Ant100 UNION removes duplicates automatically
Also you shouldn't use SELECT *
Also you really shouldn't use comma joins
 
@TehShrike ok! I hope performance won't be bad.
 
@Ant100 well, we all hope that :-P but what are you thinking of specifically?
 
@TehShrike great links! :)
@TehShrike since I don't know how big DB may be (it could be up to 10k+) I'm worried making multiple calls will slow down everything. But i think it'd still be a problem if I use join and only make one call.
 
ah, 10k is nothing
you'll still want indexes on your foreign keys though
you'll definitely want to use JOIN where appropriate
Mind pastebinning your schema and giving an example of a result you'd want to get back from it?
use SHOW CREATE TABLE [tablename] to get the schema definitions for each table
 
8:06 PM
ok this is the academics info table
[Table] => datos_academicos
[Create Table] => CREATE TABLE `datos_academicos` (
`id_datos` int(11) NOT NULL AUTO_INCREMENT,
`id_persona` int(11) NOT NULL,
`id_tipo_estudio` int(11) NOT NULL,
`nom_centro_estudios` varchar(100) CHARACTER SET utf8 COLLATE utf8_spanish_ci NOT NULL,
`fec_inicio` date NOT NULL,
`fec_fin` date DEFAULT NULL,
`grado_academico` varchar(100) CHARACTER SET utf8 COLLATE utf8_spanish_ci DEFAULT NULL,
`ciclo` varchar(10) CHARACTER SET utf8 COLLATE utf8_spanish_ci DEFAULT NULL,
for instance I want to select 'id_persona' where 'nom_centro_estudios' is 'MIT' and 'grado_academico' is 'graduate student'
or maybe select id_persona' where (nom_centro estudios LIKE mit OR nom_centro_estudios LIKE OtherSchool) AND (grado_academico = gradute student)
that shall give me a group of people
then I do a where_in to look only for people with id's that came from previous results
and I look in the next table
all tables have the same 'id_persona' column
 
 
1 hour later…
9:16 PM
@Ant100 yes, that should definitely be a single query with JOINs
SELECT other_table.id, other_table.stuff
FROM datos_academicos
JOIN other_table ON other_table.id_persona = datos_academicos.id_persona
WHERE datos_academicos.nom_centro_estudios = 'MIT' AND datos_academicos.grado_academico = 'graduate student'
 
and I can use LIKE also?
SELECT other_table.id,
FROM datos_academicos
JOIN other_table ON other_table.id_persona = datos_academicos.id_persona
WHERE (other_table.lastWork = 'IBM' OR other_table.lastWork = 'Google') AND
(datos_academicos.nom_centro = 'MIT' OR datos_academicos.nom_centro = 'OtherSchool' ) AND ...
i forgot the like lol, but yeah instead of =, I use LIKE
 
@Ant100 you can use LIKE, but if you start the comparison out with a wildcard then it won't be able to use any index: column LIKE '%something'
 
oh I see
 
You can rewrite that one section to use IN: datos_academicos.nom_centro IN('MIT", 'OtherSchool')
for that query you would want to make sure that there was an index on lastWork and another on nom_centro
But really, I'm guessing that those shouldn't be strings at all
you should have an employer table and a school table
and you should use lastWorkEmployerId instead of lastWork
 
9:34 PM
that seems like a nicer way to go. I didn't design the DB, my boss did. What I got is a table called 'school_info' (I'm translating it so it makes more sense) and there I have columns 'id', 'person_id', 'school_name', 'start_year', 'end_year'.
I do have a school table, but for some reason 'school_info' table is stored the name, not the id.
Same for table 'work-info'. It's all strings.
 
9:59 PM
Ok, I'll try to use JOIN, and I should make the columns I am lookin on (such as nom_centro) an index?
if I have two or three indexes on one table, will that affect performance?
@TehShrike about what you said of LIKE, will column LIKE 'something%' use index correctly? Or should I better avoid using LIKE? I wanted to use like because if, for instance, position is 'Assistant Manager', if user just puts in 'Assistant' he should also get 'assitant manager' as result.
 
@Ant100 if it's in a JOIN, you want an index on it
@Ant100 correct, column LIKE 'something%' would be able to use an index on column
@Ant100 that's something I would do on the client-side - surely the app knows what all the positions are
I'd guess you have some sort of autocomplete that knows that "Assistant" matches multiple positions
And it would ask the server "hey, for these multiple position identifiers, get me all people" or whatever
 
10:16 PM
@TehShrike hmm that sounds interesting. Unfortunately, I have no idea on how to implement it, lol. I'll stick with LIKE for now, but will look more into that later on.
 
10:37 PM
thanks for your time :) I'll try switching some individual queries to JOIN instead
 
11:20 PM
@TehShrike yes, it's working thanks
 

« first day (1290 days earlier)      last day (1368 days later) »