###わからないこと
配列でIDを取得してそれをもとに一覧ページを表示しています。
しかし、該当箇所でnullとなり、dd()で確認したところ、配列が途中までしか表示されておりませんでした。
すべての表示結果でそうなるわけではなく、一定数以上の件数でのみそうなっており、データ量が影響しているのではと考えております。
どうしてそうなるのかがわかっておらず、したがってどう対処すればよいのかわかっておりません。
ご教授いただければ幸いです。
※変数に格納してあるデータが1Mちょうどで収まっているのを確認しました。つまり1Mを超えたデータについては切られている状況になります。
そのため、json配列の「 ] 」も切られているので、nullが取得されていると考えています。
###コード
protected $casts = array( 'result' => 'array', 'query' => 'array', );
$data = Search::select('result', 'query')->where('id', 5)->first(); $all = $data ? $data['result'] : [];
上記の「$data['result']」にddをかけるとnullが取得されます。
※Searchはsearchesというテーブルを指します。
そのうちの「result」カラムが非常に肥大している状況です。
通常ですと、「result:[1, 2, 3, ..., 555555]」のように表示されるのですが、「 result:[1, 2, 3, ..., 555554, 」と表示されています。
###テーブル構造
Name: searches
Engine: InnoDB
Version: 10
Row_format: Dynamic
Rows: 83424
Avg_row_length: 37212
Data_length: 3104407552
Max_data_length: 0
Index_length: 0
Data_free: 7340032
Auto_increment: 89328
Create_time: 2017-07-11 23:28:01
Update_time: 2017-10-04 06:19:23
Check_time: NULL
Collation: utf8_unicode_ci
Checksum: NULL
Create_options:
Comment:
よろしくお願いいたします。
##追加事項
###モデル
protected $table = 'searches'; protected $casts = array( 'id' => 'integer', 'result' => 'array', 'query' => 'array', );
###テーブル構造
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, `result` longtext COLLATE utf8_unicode_ci NOT NULL, `query` longtext COLLATE utf8_unicode_ci NOT NULL, `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=89390 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_c
###queryの中身
array:3 [▼ "pha" => array:18 [▶] "q" => "" "pri" => [] ]
###ddの結果
Search {#987 ▼ #table: "searches" #casts: array:3 [▶] #connection: null #primaryKey: "id" #perPage: 15 +incrementing: true +timestamps: true #attributes: array:2 [▼ "result" => "[142264,142265,142266,142263,142262,142261,142260,...] "query" => "{"phase":[1,2,3,5,6,8,12,32,10,11,28,29,27,26,25,31,24,0],"q":"","privacy":[]}" ]
##追記
$search = (int)request()->input('search'); if ($search) { $data = Search::select('result', 'query')->where('id', $search)->first(); dd(strlen($data->getAttributeFromArray('result'))); $all = $data ? $data['result'] : []; $q = isset($data['query']['q']) ? $data['query']['q'] : ''; $phaseIds[0] = isset($data['query']['phase']) ? $data['query']['phase'] : []; $privacy = isset($data['query']['privacy']) ? $data['query']['privacy'] : []; } else { $phaseIds[0] = array_unique(array_map('intval', (array)request()->input('phase'))); if ($phaseIds[0]) { } elseif (request()->ajax()) { unset($phaseIds[0]); unset($phaseIds[1]); $phaseIds = array_values($phaseIds); } else { $phaseIds[0] = array_values(array_diff(last($phaseIds),(array)Option::getArray(Option::JPHASE_FINISH))); } // 検索フォームでの検索値の取得 $q = (string)request()->input('q'); // 各種ポータルサイトへの公開/非公開設定の取得 $privacy = array_unique((array)request()->input('privacy')); // 全案件のidを取得 $all = self::commitSearch($q, $phaseIds[0], $privacy); // インスタンスの生成 $search = new Search(); $search['result'] = $all; $search['query'] = ['phase'=>$phaseIds[0],'q'=>$q,'privacy'=>$privacy]; $search->save(); $search = $search['id']; }
public static function commitSearch($q, $phaseIds, $privacy, $ids = NULL) { $fulltext = Fulltext::where('type', 'job')->orderBy('time','DESC'); if ($ids) $fulltext->whereIn('main_id', $ids); if ($phaseIds) $fulltext->whereIn('phase_id', $phaseIds); if ($q !== '') $fulltext->whereIndex($q); if (!$privacy || count($privacy) === 3) { return array_map('intval', $fulltext->lists('main_id')->toArray()); } elseif (!($ids = array_map('intval', Job::whereIn('privacy', $privacy)->lists('id')->toArray()))) { return []; } elseif (count($ids) <= 10000) { $fulltext->whereIn('main_id', $ids); return array_map('intval', $fulltext->lists('main_id')->toArray()); } else { return array_values(array_intersect(array_map('intval', $fulltext->lists('main_id')->toArray()), $ids)); } }
###追記②
「strlen(getAttribute['result'])」:1041645
「substr(getAttribute['result'], -10)」:"7392,7372,"
「LENGTH(result)」:1053784
「RIGHT(result, 10)」:1576,3449]
##現状報告
調べたところ、1MBを境目にエラーが発生しているようです。
そのため、phpとmysqlの設定をあらっている現状になります。
####バージョン
php7
laravel5.1
データベース:RDS(mysql5.7)
回答3件
あなたの回答
tips
プレビュー