Osticket search not working db error 1191 - mysql

When somebody tries to search for a ticket, as admin, I get an email with this error.
OsTicket v1.11.0-rc1 (e321982)
[SELECT SQL_CALC_FOUND_ROWS A1.`number` AS `number`, A1.`ticket_id` AS `ticket_id`, A1.`source` AS `source`, A1.`created` AS `created`, A8.`subject` AS `cdata__subject`, A1.`isoverdue` AS `isoverdue`, B0.`name` AS `user__name`, A8.`priority` AS `cdata__priority`, B1.`firstname` AS `staff__firstname`, B1.`lastname` AS `staff__lastname`, B2.`name` AS `team__name`, A1.`team_id` AS `team_id`, A1.`isanswered` = '1' AS `8MwwjGf`, (SELECT COUNT(R0.`id`) AS `count` FROM `ost_thread` Q7 JOIN `ost_ticket` Q8 ON (Q7.`object_type` = 'T' AND Q7.`object_id` = Q8.`ticket_id`) LEFT JOIN `ost_thread_entry` R0 ON (Q7.`id` = R0.`thread_id`) WHERE Q8.`ticket_id` = A1.`ticket_id` AND NOT R0.`flags` & 4 != 0) AS _thread_count, (SELECT COUNT(R1.`id`) AS `count` FROM `ost_thread` Q7 JOIN `ost_ticket` Q8 ON (Q7.`object_type` = 'T' AND Q7.`object_id` = Q8.`ticket_id`) LEFT JOIN `ost_thread_entry` R0 ON (Q7.`id` = R0.`thread_id`) LEFT JOIN `ost_attachment` R1 ON (R1.`type` = 'H' AND R0.`id` = R1.`object_id`) WHERE Q8.`ticket_id` = A1.`ticket_id` AND R1.`inline` = 0) AS _att_count, COALESCE(B1.`firstname`, B1.`lastname`, B2.`name`, 'zzz') AS `assignee` FROM `ost_ticket` A1 JOIN `ost_ticket_status` A2 ON (A1.`status_id` = A2.`id`) LEFT JOIN `ost_thread` A3 ON (A3.`object_type` = 'T' AND A1.`ticket_id` = A3.`object_id`) LEFT JOIN `ost_thread_referral` A4 ON (A3.`id` = A4.`thread_id`) LEFT JOIN `ost_staff` A5 ON (A4.`object_type` = 'S' AND A4.`object_id` = A5.`staff_id`) LEFT JOIN `ost_team` A6 ON (A4.`object_type` = 'E' AND A4.`object_id` = A6.`team_id`) LEFT JOIN `ost_department` A7 ON (A4.`object_type` = 'D' AND A4.`object_id` = A7.`id`) LEFT JOIN `ost_ticket__cdata` A8 ON (A1.`ticket_id` = A8.`ticket_id`) JOIN `ost_user` B0 ON (A1.`user_id` = B0.`id`) LEFT JOIN `ost_staff` B1 ON (A1.`staff_id` = B1.`staff_id`) LEFT JOIN `ost_team` B2 ON (A1.`team_id` = B2.`team_id`) JOIN (SELECT COALESCE(Z3.`object_id`, Z5.`ticket_id`, Z8.`ticket_id`) as `ticket_id`, SUM(MATCH (Z1.title, Z1.content) AGAINST ('black8' IN NATURAL LANGUAGE MODE)) AS `relevance` FROM `ost__search` Z1 LEFT JOIN `ost_thread_entry` Z2 ON (Z1.`object_type` = 'H' AND Z1.`object_id` = Z2.`id`) LEFT JOIN `ost_thread` Z3 ON (Z2.`thread_id` = Z3.`id` AND Z3.`object_type` = 'T') LEFT JOIN `ost_ticket` Z5 ON (Z1.`object_type` = 'T' AND Z1.`object_id` = Z5.`ticket_id`) LEFT JOIN `ost_user` Z6 ON (Z6.`id` = Z1.`object_id` and Z1.`object_type` = 'U') LEFT JOIN `ost_organization` Z7 ON (Z7.`id` = Z1.`object_id` AND Z7.`id` = Z6.`org_id` AND Z1.`object_type` = 'O') LEFT JOIN ost_ticket Z8 ON (Z8.`user_id` = Z6.`id`) WHERE MATCH (Z1.title, Z1.content) AGAINST ('black8' IN NATURAL LANGUAGE MODE) GROUP BY `ticket_id`) Z1 WHERE A1.`ticket_id` = Z1.`ticket_id` AND ((A2.`state` = 'open' AND (A1.`staff_id` = 7 OR A5.`staff_id` = 7 OR A1.`team_id` IN (5) OR A6.`team_id` IN (5))) OR A1.`dept_id` IN (1, 4, 5) OR A7.`id` IN (1, 4, 5)) GROUP BY A1.`number`, A1.`ticket_id`, A1.`source`, A1.`created`, A8.`subject`, A1.`isoverdue`, B0.`name`, A8.`priority`, B1.`firstname`, B1.`lastname`, B2.`name`, A1.`team_id` LIMIT 25]
Can't find FULLTEXT index matching the column list
---- Backtrace ----
0 (root)/include/mysqli.php(199): osTicket->logDBError('DB Error #1191', '[SELECT SQL_CAL...')
1 (root)/include/class.orm.php(3404): db_query('SELECT SQL_CALC...', true, true)
2 (root)/include/class.orm.php(3451): MySqlExecutor->execute()
3 (root)/include/class.orm.php(2063): MySqlExecutor->getArray()
4 (root)/include/class.orm.php(2013): HashArrayIterator->{closure}()
5 (root)/include/class.orm.php(1992): CallbackSimpleIterator->next()
6 (root)/include/class.orm.php(2001): CallbackSimpleIterator->rewind()
7 (root)/include/class.orm.php(1673): CallbackSimpleIterator->valid()
8 (root)/include/class.orm.php(1708): CachedResultSet->fillTo(1)
9 (root)/include/class.orm.php(1569): CachedResultSet->offsetGet(0)
10 (root)/include/class.orm.php(1437): QuerySet->offsetGet(0)
11 (root)/include/class.orm.php(1394): QuerySet->exists(true)
12 (root)/include/staff/templates/queue-tickets.tmpl.php(79): QuerySet->total()
13 (root)/scp/tickets.php(543): require_once('/var/www/html/u...')
14 {main}

I ran
ALTER TABLE `ost__search` ADD FULLTEXT(title,content);
And that fixed the problem.

Related

mysql form subarray(array aggregation) and return

I have the following mysql query
select m.flat_id,
f.flat_no,
fo.owner_name,
oc.occupant_name,
b.block_name,
f.floor_no,
f.floor_id,
m.user_id as user_map_id
from svk_apt_flats_users_mapping m
left join svk_apt_users u on u.user_id = m.user_id and u.association_id = 2
and u.customer_id = 2 and u.is_active = 1 and u.user_id is not null
left join svk_apt_flats f on f.flat_id = m.flat_id and f.is_active = 1
left join svk_apt_blocks b on b.block_id = f.block_id and b.is_active = 1
left join svk_apt_flat_owners fo on u.user_role_type_id = 4 and fo.is_active = 1 and fo.user_id = m.user_id
left join svk_apt_occupants oc on u.user_role_type_id = 5 and oc.is_active = 1 and oc.user_id = m.user_id
where f.block_id = 3
and m.user_id <> 2
and m.customer_id = 2
and m.association_id = 2
and m.is_active = 1
and m.is_active = 1
and (case when m.user_role_type_id = 5 then true else m.is_approved = 1 end)
and Output :
I want to aggregate the rows who have same 'user_map_id' into one row.
Is there any solutions in mysql ?
Use group by
select m.flat_id,
f.flat_no,
fo.owner_name,
oc.occupant_name,
b.block_name,
f.floor_no,
f.floor_id,
m.user_id as user_map_id
from svk_apt_flats_users_mapping m
left join svk_apt_users u on u.user_id = m.user_id and u.association_id = 2
and u.customer_id = 2 and u.is_active = 1 and u.user_id is not null
left join svk_apt_flats f on f.flat_id = m.flat_id and f.is_active = 1
left join svk_apt_blocks b on b.block_id = f.block_id and b.is_active = 1
left join svk_apt_flat_owners fo on u.user_role_type_id = 4 and fo.is_active = 1 and fo.user_id = m.user_id
left join svk_apt_occupants oc on u.user_role_type_id = 5 and oc.is_active = 1 and oc.user_id = m.user_id
where f.block_id = 3
and m.user_id <> 2
and m.customer_id = 2
and m.association_id = 2
and m.is_active = 1
and m.is_active = 1
and (case when m.user_role_type_id = 5 then true else m.is_approved = 1 end)
group by u.user_role_type_id;
MySQL will pick the values of the first row for all columns if you do not specifiy an aggregate function like SUM, AVG etc. onto them

How to get the child count for parent child relationship

Using this query will get the result as in shown in below image link
select c.property_title,b.property_title as building,d.property_title as floor,e.house_name as house,
f.room_no as room,g.bed_no as bed
from g_property_group c
left join g_property_group b on b.parent_id = c.id and b.is_deleted = '0'
left join g_property_group d on d.parent_id = b.id and d.is_deleted = '0'
left join g_house e on e.property_group_id = d.id and e.is_deleted = '0'
left join g_room f on f.house_id = e.id and f.is_deleted = '0'
left join g_bed g on g.room_id = f.id and g.is_deleted = '0'
where c.id = 'a976df373f75d3f8cc49938ae9fead8e4fc8ad19'
and c.is_deleted = '0'
I have written the query for fetching the count of parent and child .will get the building count as 7 floor count as 7 house count as 5 room count as 4, instead the count of building should be 2, floor = 2, house = 4, Rooms = 5 and Bed 1.
select c.property_title,count(b.property_title)as building,count(d.property_title)as floor,count(e.house_name)as house,
count(f.room_no)as room,count(g.bed_no) as bed
from g_property_group c
left join g_property_group b on b.parent_id = c.id and b.is_deleted = '0'
left join g_property_group d on d.parent_id = b.id and d.is_deleted = '0'
left join g_house e on e.property_group_id = d.id and e.is_deleted = '0'
left join g_room f on f.house_id = e.id and f.is_deleted = '0'
left join g_bed g on g.house_id = g.id and g.room_id = f.id and g.is_deleted = '0'
where c.id = 'a976df373f75d3f8cc49938ae9fead8e4fc8ad19'
and c.is_deleted = '0'
Thank you in advance
Try this:
SQL SERVER
select count([building]) over (order by building) as [bulding count],
count([floor]) over (order by [floor],[building]) as [floor count],
count([house]) over (order by building,[floor],[house]) as [house count],
count([room]) over (order by building,[floor],[house],[room]) as [room count],
count([bed]) over (order by building,[floor],[house],[room],[bed]) as [room count]

Why MYSQL doesn't use my indexes?

I have table karton00 which holds thousands of records. This makes the queries slow. I would like to use indexes, but even though I set them, they are not being used.
Here is my table. and here is the result of using EXPLAIN.
This is my query:
SELECT '' checkbox,
k00_eszkozid,
k00_eszkoznev,
k01_gyariszam,
k01_leltszam,
prsn_name,
k00_status,
tstikon,
k00_startflow,
tstname,
k00_eszkozid,
k01_gyariszam,
k01_leltszam
FROM karton00
LEFT JOIN karton01
ON k00_eszkozid = k01_eszkozid
AND k01_status = 'A'
LEFT JOIN karton02
ON k00_eszkozid = k02_eszkozid
AND k02_status = 'A'
LEFT JOIN karton04
ON k00_eszkozid = k04_eszkozid
AND k04_status = 'A'
LEFT JOIN karton05
ON k00_eszkozid = k05_eszkozid
AND k05_status = 'A'
LEFT JOIN karton06
ON k00_eszkozid = k06_eszkozid
AND k06_status = 'A'
LEFT JOIN karton08
ON k00_eszkozid = k08_eszkozid
AND k08_status = 'A'
LEFT JOIN karton09
ON k00_eszkozid = k09_eszkozid
AND k09_status = 'A'
LEFT JOIN telephely et
ON k06_telephelyid = et.telepid
LEFT JOIN ktghely00 ek
ON k02_ktghid = ek.ktghid
LEFT JOIN person00 us
ON k06_userid = prsn_id
LEFT JOIN ktghely00 fk
ON prsn_ktgh = fk.ktghid
LEFT JOIN telephely ft
ON prsn_telep = ft.telepid
LEFT JOIN tamstatus
ON k02_tamstatusid = tstid
LEFT JOIN szakleltar
ON k02_szakleltarid = szleltid
LEFT JOIN tamszerv
ON k02_tamszervid = tszid
LEFT JOIN ktghely01
ON k02_vgazdaid = vgid
AND vgstatus = 'A'
LEFT JOIN ktghely00 vk
ON vgktghid = vk.ktghid
LEFT JOIN szallitok m
ON k05_mincegid = m.szallid
LEFT JOIN szallitok s
ON k04_szallitoid = s.szallid
LEFT JOIN dctnry00 ym
ON k05_minosit = ym.dctnryname
AND ym.dctnrygrp = 'YESNO'
LEFT JOIN dctnry00 yd
ON k05_check = yd.dctnryname
AND yd.dctnrygrp = 'YESNO'
WHERE k00_status IN ( 'A', 'H' )
AND ( k02_vgazdaid IN ( 7 ) )
AND NOT EXISTS (SELECT *
FROM eszkozkizar
WHERE ez_flid = 0
AND ez_emintaid = k00_eszkozmintaid
AND k00_uzembedatum < ( Date_add(Curdate(),
INTERVAL ez_honap month) )
AND k00_uzembedatum != ''
AND k02_vgazdaid NOT IN ( 7 ))
AND NOT EXISTS(SELECT *
FROM eszkozkizar
WHERE ez_flid = 0
AND ez_emintaid = k00_eszkozmintaid
AND k02_tamszervid = ez_tamszerv
AND k02_tamstatusid = ez_tamsts
AND k00_uzembedatum < ( Date_add(Curdate(),
INTERVAL ez_honap month) )
AND k00_uzembedatum != ''
AND k02_vgazdaid NOT IN ( 7 ))
ORDER BY k00_eszkoznev ASC;
Also you can use USE INDEX (index_list) statement: http://dev.mysql.com/doc/refman/5.5/en/index-hints.html

mysql query hotel availability (Not calculate the total price)

Search the list of accommodation and the total price..
Here is my query and output: http://sqlfiddle.com/#!2/eaf58/43
query:
SELECT count(candidates.accommodation_id) as total, candidates.accommodation_id, omc_accommodation_season_period.season_id,
room_1, r1_price.price_normal AS room_1_price,
(SELECT SUM(room1_price.price_normal)
FROM omc_accommodation_room_pricelist room1_price
INNER JOIN omc_accommodation_room room1
ON room1_price.accommodation_id = room1.accommodation_id
INNER JOIN omc_accommodation_season_period so1
ON room1_price.accommodation_id = so1.accommodation_id
AND room1_price.season_id = so1.season_id
INNER JOIN omc_accommodation accommodation1
ON room1_price.accommodation_id = accommodation1.id
WHERE
so1.date BETWEEN '2013-08-13' AND '2013-08-15' AND
room1.quantity >= 3 AND room1.pax_max = 1 AND
accommodation1.id = candidates.accommodation_id AND
room1.id = room_1) AS room_1_sum,
room_2,r2_price.price_normal AS room_2_price,
omc_accommodation_season_period.date
FROM (SELECT r1.accommodation_id, r1.id AS room_1,
r2.id AS room_2, r1.quantity AS room_1_quantity,
r2.quantity AS room_2_quantity
FROM
omc_accommodation_room r1
INNER JOIN
omc_accommodation_room r2 ON r1.accommodation_id = r2.accommodation_id
WHERE
r1.quantity >= 3 AND r2.quantity >= 4 AND r1.pax_max = 1 AND r2.pax_max = 2) AS candidates
LEFT JOIN omc_accommodation_season_period
ON candidates.accommodation_id = omc_accommodation_season_period.accommodation_id
AND date BETWEEN '2013-08-13' AND '2013-08-15'
AND omc_accommodation_season_period.date <> 0
LEFT JOIN omc_accommodation_room_extra_quota eq1
ON (candidates.accommodation_id = eq1.accommodation_id
AND room_1 = eq1.room_type_id
AND eq1.date=omc_accommodation_season_period.date)
LEFT JOIN omc_accommodation_room_extra_quota eq2
ON (candidates.accommodation_id = eq2.accommodation_id
AND room_2 = eq2.room_type_id
AND eq2.date=omc_accommodation_season_period.date)
LEFT JOIN omc_accommodation
ON candidates.accommodation_id = omc_accommodation.id
LEFT JOIN omc_accommodation_room_pricelist r1_price
ON (candidates.accommodation_id = r1_price.accommodation_id
AND room_1= r1_price.room_type_id)
LEFT JOIN omc_accommodation_room_pricelist r2_price
ON (candidates.accommodation_id = r2_price.accommodation_id
AND room_1 = r2_price.room_type_id)
WHERE
r1_price.season_id = omc_accommodation_season_period.season_id
AND
r2_price.season_id = omc_accommodation_season_period.season_id
GROUP BY candidates.accommodation_id, omc_accommodation_season_period.date
Problem is just to calculate the total price of each room..
Help me fix it up..
Many thanks in advance
SELECT rsp1.date, rsp1.season_id, r1.hotel_id, r1.id AS room_1, rp1.price_normal AS room_1_price, SUM(rp1.price_normal) AS room_1_total, r2.id AS room_2, rp2.price_normal AS room_2_price
FROM
omc_hotel_room r1
LEFT JOIN omc_hotel_room r2 ON r1.hotel_id = r2.hotel_id
INNER JOIN omc_hotel_room_pricelist rp1 ON r1.hotel_id = rp1.hotel_id AND r1.id = rp1.room_type_id
INNER JOIN omc_hotel_room_pricelist rp2 ON r1.hotel_id = rp1.hotel_id AND r2.id = rp2.room_type_id
LEFT JOIN omc_hotel_season_period rsp1 ON r1.hotel_id = rsp1.hotel_id
WHERE
r1.pax_max = 1 AND
rp1.price_normal <> 0 AND
r2.pax_max = 2 AND
rp2.price_normal <> 0 AND
rsp1.date BETWEEN '2013/08/13' AND '2013/08/15'
GROUP BY r1.hotel_id, rsp1.date

mysql select query

I've got 2 tables: interviews & interview_keywords.
An interview has 5 sorted keywords. I need a list of interviews with specified keywords in the right positions of the sorted list. This is what I've got so far, which isn't working:
SELECT i.id,
i.title
FROM interviews AS i
LEFT JOIN interview_keywords AS ik ON i.id = ik.interview_id
WHERE i.cat_id = 1
AND ( (ik.keyword_id = 39 AND ik.sort = 1)
AND (ik.keyword_id = 33 AND ik.sort = 2)
AND (ik.keyword_id = 51 AND ik.sort = 3)
AND (ik.keyword_id = 96 AND ik.sort = 4)
AND (ik.keyword_id = 97 AND ik.sort = 5))
SELECT i.id, i.title
FROM interviews i
INNER JOIN interview_keywords ik1
ON ik1.interview.id = i.id
AND ik.keyword_id = 39
AND ik1.sort = 1
INNER JOIN interview_keywords ik2
ON ik2.interview.id = i.id
AND ik2.keyword_id = 33
AND ik2.sort = 2
INNER JOIN interview_keywords ik3
ON ik3.interview.id = i.id
AND ik3.keyword_id = 51
AND ik3.sort = 3
INNER JOIN interview_keywords ik4
ON ik4.interview.id = i.id
AND ik4.keyword_id = 96
AND ik4.sort = 4
INNER JOIN interview_keywords ik5
ON ik5.interview.id = i.id
AND ik5.keyword_id = 97
AND ik5.sort = 5
WHERE i.cat_id = 1