@@ -258,10 +258,23 @@ export class AIQueryService {
258258 parts . push ( table . description ) ;
259259 }
260260 parts . push ( "" ) ;
261+
262+ // Identify core columns
263+ const coreColumns = Object . values ( table . columns )
264+ . filter ( ( col ) => col . coreColumn === true )
265+ . map ( ( col ) => col . name ) ;
266+ if ( coreColumns . length > 0 ) {
267+ parts . push ( `Core columns (use these as defaults): ${ coreColumns . join ( ", " ) } ` ) ;
268+ parts . push ( "" ) ;
269+ }
270+
261271 parts . push ( "Columns:" ) ;
262272
263273 for ( const col of Object . values ( table . columns ) ) {
264274 let colDesc = `- ${ col . name } (${ col . type } )` ;
275+ if ( col . coreColumn ) {
276+ colDesc += " [CORE]" ;
277+ }
265278 if ( col . description ) {
266279 colDesc += `: ${ col . description } ` ;
267280 }
@@ -350,13 +363,16 @@ HAVING cnt > 10
350363
351364## Important Rules
352365
353- 1. ALWAYS use the validateTSQLQuery tool to check your query before returning it
354- 2. If validation fails, fix the issues and try again (up to 3 attempts)
355- 3. Use column names exactly as defined in the schema (case-sensitive)
356- 4. For enum columns like status, use the allowed values shown in the schema
357- 5. Always include a LIMIT clause (default to 100 if not specified)
358- 6. Use meaningful column aliases with AS for aggregations
359- 7. Format queries with proper indentation for readability
366+ 1. NEVER use SELECT * - ClickHouse is a columnar database where SELECT * has very poor performance
367+ 2. Always select only the specific columns needed for the request
368+ 3. When column selection is ambiguous, use the core columns marked [CORE] in the schema
369+ 4. ALWAYS use the validateTSQLQuery tool to check your query before returning it
370+ 5. If validation fails, fix the issues and try again (up to 3 attempts)
371+ 6. Use column names exactly as defined in the schema (case-sensitive)
372+ 7. For enum columns like status, use the allowed values shown in the schema
373+ 8. Always include a LIMIT clause (default to 100 if not specified)
374+ 9. Use meaningful column aliases with AS for aggregations
375+ 10. Format queries with proper indentation for readability
360376
361377## Response Format
362378
@@ -431,13 +447,15 @@ HAVING cnt > 10
431447
432448## Important Rules
433449
434- 1. ALWAYS use the validateTSQLQuery tool to check your modified query before returning it
435- 2. If validation fails, fix the issues and try again (up to 3 attempts)
436- 3. Use column names exactly as defined in the schema (case-sensitive)
437- 4. For enum columns like status, use the allowed values shown in the schema
438- 5. Always include a LIMIT clause (default to 100 if not specified)
439- 6. Preserve the user's existing query structure and style where possible
440- 7. Only make the changes specifically requested by the user
450+ 1. NEVER use SELECT * - ClickHouse is a columnar database where SELECT * has very poor performance
451+ 2. If the existing query uses SELECT *, replace it with specific columns (use core columns marked [CORE] as defaults)
452+ 3. ALWAYS use the validateTSQLQuery tool to check your modified query before returning it
453+ 4. If validation fails, fix the issues and try again (up to 3 attempts)
454+ 5. Use column names exactly as defined in the schema (case-sensitive)
455+ 6. For enum columns like status, use the allowed values shown in the schema
456+ 7. Always include a LIMIT clause (default to 100 if not specified)
457+ 8. Preserve the user's existing query structure and style where possible
458+ 9. Only make the changes specifically requested by the user
441459
442460## Response Format
443461
0 commit comments